我的问题的元素是我要保持3个元素,如按钮比如我使用了一个RelativeLayout
作为家长和LinearLayout
,因为它的孩子,给android:weightSum="3"
并添加3个按键,因为它的孩子。我已经实现了我想要的用户界面。 但是这里出现原始问题当按钮可见性状态之一消失了。元素不正确。对齐使用相对布局
即使当我隐藏一个按钮,其他两个按钮需要调整时,我该如何实现。
请提供解决方案,如果您有。
Respective Code
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:orientation="horizontal"
android:weightSum="3.0">
<Button
android:id="@+id/btn1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_weight="1.0"
android:textColor="#ffffff"
android:text="TAB1" />
<Button
android:id="@+id/btn2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1.0"
android:text="TAB 2"
android:visibility="gone" />
<Button
android:id="@+id/btn3"
android:layout_width="wrap_content"
android:layout_alignParentLeft="true"
android:layout_height="wrap_content"
android:layout_weight="1.0"
android:text="TAB 3" />
</LinearLayout>
</RelativeLayout>
</LinearLayout>
发表您的布局 –
安置自己隐藏一个按钮 –
集可视性,之后隐形UI,使这个问题得到解决。如果你设置了Gone,那么它会删除那个空间,但是如果你设置了Invisible,那么它将只隐藏UI,但是设置空间为你设置的重量 例如。 texview.setVisibility(查看。无形); –