android - getmeasuredheight() and getmeasuredwidth() returns 0 after View.measure() -
after measuring view
constant dimensions view.measure()
, getmeasuredheight()
, getmeasurewidth()
returning 0.
layout_view.xml, layout inflated create view
<framelayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="100dp" android:layout_height="100dp"> </framelayout>
function measures dimensions
public void measureview(context context){ layoutinflater inflater = (layoutinflater) context.getsystemservice(context.layout_inflater_service); view view = inflater.inflate(r.layout.layout_view,null,false); view.measure( view.measurespec.unspecified, view.measurespec.unspecified); log.d(tag,"error width : " + view.getmeasuredwidth()); log.d(tag,"error heeght : " + view.getmeasuredheight()); }
are measuring view in oncreate()
. view isn't drawn yet. have wait until time after view drawn before can measure it.
simple solution post runnable layout. runnable executed after layout has happened.
for more info see post
edit seek change
view.measure( view.measurespec.unspecified, view.measurespec.unspecified);
to
view.measure( view.measurespec.exactly, view.measurespec.exactly);
android layout view
No comments:
Post a Comment