java将可见按钮移到不可见按钮上
好吧,我英语说得不好,所以很难解释我想要什么
我在安卓系统中有一个自定义对话框,带有2Buttons
<LinearLayout 安卓:layout_width="fill_parent"
安卓:layout_height="wrap_content"
安卓:orientation="horizontal"
安卓:padding="10dp">
<Button 安卓:id="@+id/button_ok"
安卓:layout_width="fill_parent"
安卓:layout_height="wrap_content"
安卓:layout_weight="1"
安卓:layout_marginRight="5dp"
安卓:background="@drawable/dialog_button_background_selector"
style="@style/text_big_bold_inverted"
安卓:text="@string/ok"/>
<Button 安卓:id="@+id/button_cancel"
安卓:layout_width="fill_parent"
安卓:layout_height="wrap_content"
安卓:layout_weight="1"
安卓:layout_marginRight="5dp"
安卓:background="@drawable/dialog_button_background_selector"
style="@style/text_big_bold_inverted"
安卓:text="@string/cancel"/>
</LinearLayout>
现在,有时我只需要OK Button
,我会让cancel Button
不可见。
但是OK Button
保持在左边,当另一个不可见时,是否可以将Button
移动到中间
我试着使用.setGravity
,但没有成功
# 1 楼答案
首先将
android:layout_gravity="center_horizontal"
设置为线性布局然后,而不是视图。不可见使用视图。巴顿走了
# 2 楼答案
将“取消”按钮的可见性设置为“查看”。看不见了。看得见