Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/198.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何从xml元素中获取成员值_Android_Xml - Fatal编程技术网

Android 如何从xml元素中获取成员值

Android 如何从xml元素中获取成员值,android,xml,Android,Xml,当然,上面的代码不起作用。如何从x中获取高度,例如,将该值乘以2。可能吗?或者我应该为此定义一些约束条件?试试这个 <EditText android:id="@+id/x" android:layout_width="wrap_content" android:layout_height="match_parent"/> <EditText android:id="@+id/y" android:layout_width="match

当然,上面的代码不起作用。如何从
x
中获取高度,例如,将该值乘以2。可能吗?或者我应该为此定义一些约束条件?

试试这个

<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">
//Java
@Override
protected void onCreate(Bundle savedInstanceState) {
    EditText x = findViewById(R.id.x);
    EditText y = findViewById(R.id.y);

    y.setHeight(x.getHeight() * 2);
}