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

Popular posts from this blog

delphi - How to convert bitmaps to video? -

jasper reports - Fixed header in Excel using JasperReports -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -