2017-08-16 105 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(); 
    } 
} 
相關問題