Android: Get the size of the Body Layout Dynamically

前端 未结 3 1504
南方客
南方客 2021-01-06 16:10

I want to get the height/width of the Middle(Body) layout in onCreate() method.

My main.xml is :



        
3条回答
  •  迷失自我
    2021-01-06 16:52

    I find overriding the following method prevents the width and height being 0. At this stage of the Activity all of the View's in the Activity should be inflated.

    public void onWindowFocusChanged (boolean hasFocus)
    {
         super.onWindowFocusChanged(hasFocus);
         ScrollView scrollView = (ScrollView) findViewById(R.id.svtest);
         int width = scrollView.getWidth();
         int height = scrollView.getHeight();
    }
    

提交回复
热议问题