开发者

android get drawable area in onCreate method

if I have a layout with fill_parent at height and width, is there a way to get his height and width in onCreate method? if n开发者_如何学Goot, when his dimensions are available? I need this because I need to add at runtime some views and I need to know how many views fill in the layout.


You can do that:. Suppose you have the layout view in onCreate method

     layout.post(new Runnable() {
        @Override
          public void run() {
            height= getHeight();
            width=getWidth();        
            //pupulate other views now that you know the parent size     
            }
        }
  });


You can use the onSizeChanged method to get the information when it has been calculated, but this may also help to at least get the dimensions of the display.

Display display = ((WindowManager) getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay(); 
int width = display.getWidth(); 

You may find this useful:

when is onSizeChanged() called?

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜