【发布时间】:2014-01-13 21:02:32
【问题描述】:
我有一个按钮Add new address,当按下它时,我想显示EditText 字段以收集新地址详细信息。是否有任何布局可以做到这一点。或者当 Button 未按下时隐藏文本字段,这是唯一的方法吗?
【问题讨论】:
-
只需编辑文本并使其不可见,然后在按钮单击事件中将其设置为可见。
我有一个按钮Add new address,当按下它时,我想显示EditText 字段以收集新地址详细信息。是否有任何布局可以做到这一点。或者当 Button 未按下时隐藏文本字段,这是唯一的方法吗?
【问题讨论】:
在布局中定义编辑框如下 -
<LinearLayout
android:id="@+id/exp_linear_layout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<EditText
android:id="@+id/exp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginTop="10dp"
/>
</LinearLayout>
现在使用布局 id 来获取如下视图。
LinearLayout l=(LinearLayout)findViewById(R.id.exp_linear_layout);
只需切换按钮点击事件的可见性 -
l.setVisibility(View.GONE) and vice versa.
希望对你有帮助。
【讨论】:
没有内置的框架可以做到这一点。您可以通过将View.SetVisibility() 设置为可见或消失来执行此操作。最初按钮是可见的,但文本字段是不可见的。当用户单击按钮时,您可以将此按钮的可见性设置为不可见或在文本字段中消失和可见。
【讨论】: