I’m trying my app format some images in the screen after the Activity loads. The problem is while inside onCreate(), onResume() methods my ImageView have width and height=0. How can I run some code after the views are resized?
I test onPostResume() but it dont work =(
I’m trying my app format some images in the screen after the Activity loads.
Share
Views in Android do not have fixed size/position like in Blackberry or iPhone; instead, they are layed out dynamically. Layout happens much later than
onCreate/onResume, and theoretically can happen many times. Every view has methodsonMeasureandonLayoutwhich are responsible for that. Only afteronLayoutmethod returns you can tell the view’s size and position. Before that the view’s size is 0 and position is 0 (as you’ve noticed).So it makes little sense trying to get ImageView’s size in
onCreate/onResumebecauseonLayouthasn’t yet been called at that point.Instead, override
onLayoutlike this and do your stuff there: