我需要相对/线性布局的运行时尺寸。
activity_home.xml:
<RelativeLayout
android:id="@+id/rlParent"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</RelativeLayout>
HomeActivity.java:
private int width, height;
RelativeLayout rlParent = (RelativeLayout) findViewById(R.id.rlParent);
w = rlParent.getWidth();
h = rlParent.getHeight();
Log.i("Width-Height", width+"-"+height);
请分享您的想法。
最佳答案
试试这个
@Override
public void onWindowFocusChanged(boolean hasFocus) {
// TODO Auto-generated method stub
super.onWindowFocusChanged(hasFocus);
updateSizeInfo();
}
private void updateSizeInfo() {
RelativeLayout rlayout = (RelativeLayout) findViewById(R.id.rlayout);
w = rlayout.getWidth();
h = rlayout.getHeight();
Log.v("W-H", w+"-"+h);
}
关于android - 如何以编程方式获取相对的宽度和高度 - android中的线性布局?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20547974/