How do you access a custom view's android:layout_width and android:layout_height parameters? -
how access custom view's android:layout_width , android:layout_height values?
sample xml:
<com.example.custombutton android:id="@+id/btn" android:layout_width="150dp" android:layout_height="70dp" />
in custombutton:
@override protected void onmeasure(int widthspec, int heightspec) { int measuredwidth = measurespec.getsize(widthspec); int measuredheight = measurespec.getsize(heightspec); // how can measure based on android:layout_width, android:layout_height? // implementation measures off parent's values setmeasureddimension(measuredwidth, measuredheight); }
you must layout params of view:
custombutton.layoutparams viewparams = yourview.getlayoutparams();
and can access or modify width or view:
viewparams.height; viewparams.width;
hope helps!
Comments
Post a Comment