Android set height and width of Custom view programmatically Ask Question

Android set height and width of Custom view programmatically Ask Question

I have created a custom view named Graphview . Here is the structure for the GraphView class.

public class GraphView extends View {

    public GraphView(Context context, float[] values, String title, String[] horlabels, String[] verlabels, boolean type) {
        super(context);
                ........
   }

   ..................
   .................
}

を使用してテーブル行にビューを追加しましたaddview()。問題なく動作しています。次に、 の高さと幅を設定したいと思いますGraphView。どうすればいいでしょうか?

ベストアンサー1

高さと幅は次のように設定できます。

myGraphView.setLayoutParams(new LayoutParams(width, height));

おすすめ記事