2017-08-16 111 views
0

编程中的新功能。下面的代码正在获取设备的屏幕尺寸。这是我的问题。我怎样才能取代这个代码来获得我的relativelayout的宽度和高度?如何获得我的布局的高度和宽度

windowwidth = getWindowManager().getDefaultDisplay().getWidth(); 
    windowheight = getWindowManager().getDefaultDisplay().getHeight(); 
+0

你想要的屏幕尺寸相对layou的尺寸?? –

回答

0

这应该让你去

RelativeLayout relLayout = (RelativeLayout) findViewById(R.id.layout_file); 
int width = relLayout.getWidth(); 
int height = relLayout.getHeight(); 

免责声明:我没有得到一个机会来测试该代码。

0

试试看看这个代码。这个对我有用。

RelativeLayout = relativeLayout = findViewById(R.id.id_of_relativeLayout); 

relativeLayout.post(new Runnable() { 
    @Override 
    public void run() { 
     int width = relativeLayout.getWidth(); 
     int height = relativeLayout.getHeight(); 
    } 
} 
相关问题