Android 以编程方式将layout_bellow属性字段更改为另一个字段
给定以下代码:Android 以编程方式将layout_bellow属性字段更改为另一个字段,android,android-layout,android-relativelayout,textview,Android,Android Layout,Android Relativelayout,Textview,给定以下代码: <RelativeLayout android:id="@+id/rel" android:layout_width="match_parent" android:layout_height="wrap_content" > <TextView android:id="@+id/textPersonalInfoEmpty" android:layout_width="wrap_content"
<RelativeLayout
android:id="@+id/rel"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/textPersonalInfoEmpty"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_marginTop="20dp"
android:hint="Edit to set your personal info"
android:textSize="16sp"
android:visibility="gone" />
<EditText
android:id="@+id/editName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_marginTop="15dp"
android:hint="Name"
android:visibility="gone"
android:textSize="16sp" />
<Button
android:id="@+id/insertGameId"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/editName"
android:layout_marginTop="20dp"
android:text="Insert" />
</RelativeLayout>
TextView和EditText是可见的,这取决于用户的交互,并且两者永远不会同时可见。一次一个
问题是第三个组件(按钮)需要根据哪个组件可见来更改下面的属性android:layout_
我需要以编程的方式来解决这个问题
有什么帮助吗?对文本视图和编辑文本使用Relativelayout。和relativelayout的高度:包裹内容 然后给你的亲戚一个身份证 然后将这一行添加到按钮的xml文件中
<Button
android:layout_below="@id/RealtiveLayoutid" />
仅此而已首先,使用切换按钮而不是按钮。它可以具有您指定给它的所有属性 接下来,将其添加到ToggleButton:
<ToggleButton
....
android:textOn="@string/ifTextView"
android:textOff="@string/ifTextBox"
android:onClick="onToggleClicked"
/>
记住导入所需的类
public void onToggleClicked(View v) {
boolean on = ((ToggleButton) v).isChecked();
if(on) {
theTextView.setVisibility(View.VISIBLE);
theTextBox.setVisibility(View.INVISIBLE);
} else {
theTextBox.setVisibility(View.VISIBLE);
theTextView.setVisibility(View.INVISIBLE);
}
}