我正在使用带有 6 个按钮的线性布局。
根据权限,将按钮设置为可见或不可见。
按钮1 按钮2 按钮3 按钮4 按钮5 按钮6
基于用户权限
按钮1
按钮3 按钮4
按钮6
我的问题是:有没有办法让显示为
按钮1 按钮3 按钮4 按钮6
布局的 android xml 可以管理这个吗?如果可以,如何管理?
最佳答案
这是您的布局,请检查。
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="6" >
<Button
android:id="@+id/btn1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Button 1" />
<Button
android:id="@+id/btn2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Button 2"
android:visibility="gone" />
<Button
android:id="@+id/btn3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Button 3" />
<Button
android:id="@+id/btn4"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Button 4" />
<Button
android:id="@+id/btn5"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Button 5"
android:visibility="gone" />
<Button
android:id="@+id/6"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Button 6" />
</LinearLayout>
关于android - 如何使用线性布局填充空间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25400050/