你好我有興趣使用android獲取佈局的寬度和高度,一旦佈局已經加載,然後根據這些測量來創建圖片,文本框,具有適當尺寸的按鈕對於我的遊戲遇到的Android設備! 這怎麼可能?在哪些功能我應該把以下代碼:獲取佈局的寬度和高度創建表單後
layout.getWidth();
layout.getHeight();
所以它不會返回0?這將是一個很多更方便的實現上述獲取形式實際上加載之前但是從我所看到的這個困難得多 這是到目前爲止我的代碼試圖獲得這些測量的寬度和高度:
protected void onStart() {
super.onStart();
txt = (TextView) findViewById(R.id.textView);
img = (ImageView) findViewById(R.id.imageView2);
layout = (RelativeLayout) findViewById(R.id.MyLayout);
GameHandler();
}
public void GameHandler()
{
txt.setText(""+layout.getHeight()) ; //this always returns 0
}
謝謝你的幫助:)