<EditText
android:id="@+id/x"
android:layout_width="wrap_content"
android:layout_height="match_parent"/>
<EditText
android:id="@+id/y"
android:layout_width="match_parent"
android:layout_height="x.layout_height*2">
上面的代码当然不起作用。如何从 x
获取高度,例如将此值乘以 2。这可能吗?或者我应该为此定义一些约束?
最佳答案
试试这个
//Java
@Override
protected void onCreate(Bundle savedInstanceState) {
EditText x = findViewById(R.id.x);
EditText y = findViewById(R.id.y);
y.setHeight(x.getHeight() * 2);
}
关于android - 如何从 xml 元素中获取成员值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54933157/