java - Custom View Width -
i've created class custom view, , overrode onmeasure method show next. when call getter width , height, returns 0. why happen?
@override protected void onmeasure(int widthmeasurespec, int heightmeasurespec){ super.onmeasure(widthmeasurespec, heightmeasurespec); int parentwidth = measurespec.getsize(widthmeasurespec); int parentheight = measurespec.getsize(heightmeasurespec); this.setmeasureddimension(parentwidth, parentheight); }
the getwidth() , getheight() values available after first full layout pass (onmeasure -> onlayout) if need access values in between use getmeasuredwidth() , getmeasuredheight()
Comments
Post a Comment