Android set height and width of Custom view programmatically -
i have created custom view named graphview
. here structure graphview class.
public class graphview extends view { public graphview(context context, float[] values, string title, string[] horlabels, string[] verlabels, boolean type) { super(context); ........ } .................. ................. }
i have added view in tablerow using addview()
. working fine. want set height , width graphview
. how that?
the easy way set size programatically :
graphview.setlayoutparams(new layoutparams(width, height));
this fine if know exact size of view. however, if want more flexible approach, can override onmeasure()
method measure view more precisely depending on space available , layout constraints (wrap_content
, match_parent
, or fixed size).
you can find example on how override onmeasure()
looking @ android docs , labelview
sample in sdk directory.
Comments
Post a Comment