开发者

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 assuming this is because the views have not been drawn yet. At what point are views drawn and is 开发者_如何学Gothere a callback I can put my code so I can get the size of the view?

findViewById(R.id.header).getHeight();


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.


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

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜