Android:固定线性布局中的宽度

时间:2013-07-10 14:05:39

标签: android android-linearlayout multiple-columns fixed android-layout-weight

我有以下布局

LinearLayout
    orientation:horizontal

    CheckBox
        visibility:invisible
        layout_weight:0

    TextView
        layout_weight:1

    TextView
        layout_weight:1

    TextView
        layout_weight:1

    TextView
        layout_weight:1

点击后,我的ActionBar中有一个EDIT按钮使CheckBox可见

问题在于,当显示复选框时,所有TextView都向右移动

有什么方法可以让CheckBox列固定宽度,以免影响其他部分?

1 个答案:

答案 0 :(得分:0)

我测试了这段代码,当它可见时它不会跳转:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="horizontal" >

    <CheckBox
        android:visibility="invisible"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>

    <TextView
        android:text="test"
        android:layout_weight="1"
        android:layout_width="0dp"
        android:layout_height="wrap_content"/>
    <TextView
        android:text="test"
        android:layout_weight="1"
        android:layout_width="0dp"
        android:layout_height="wrap_content"/>
    <TextView
        android:text="test"
        android:layout_weight="1"
        android:layout_width="0dp"
        android:layout_height="wrap_content"/>
    <TextView
        android:text="test"
        android:layout_weight="1"
        android:layout_width="0dp"
        android:layout_height="wrap_content"/>
</LinearLayout>

如果您在任何时候,使您的复选框的可见性消失,它将不会“保留”其空间。