Skip to content Skip to sidebar Skip to footer

When Are Views Drawn In Android?

I want to get the size of a view that is in my activity but I am not able to get that information in any of the activity lifecycle callbacks (onCreate, onStart, onResume). I'm ass

Solution 1:

How are views drawn provides a good overview of the process of drawing views. Basically, there is a pass where the measure what everything wants to be, and then a second pass when things are layed out.

It sounds like for your problem though, you should be able to accomplish your goal with resorting to setting height values by hand. Have you played around with the stretchMode, gravity, layoutHeight, etc of your gridview? See GridView javadoc for some details of the param choices.

Solution 2:

It should work in onCreate(), onStart(), and onResume() after you've instantiated your layouts. Try:

findViewById(R.id.header).getLayoutParams().height

Post a Comment for "When Are Views Drawn In Android?"