裁剪布局中的元素

Elements in layout cropped

我的布局文件有问题,当我在 Android 4.1 的设备上测试它时,我不知道为什么会这样,所以这是我得到的:

这是布局的一部分:

<LinearLayout
            android:id="@+id/chooseType"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:visibility="visible"
            android:layout_marginLeft="16dp"
            android:layout_marginStart="16dp"
            android:layout_marginRight="16dp"
            android:layout_marginEnd="16dp"
            android:layout_marginTop="12dp"
            android:orientation="horizontal">


            <CheckBox
                android:id="@+id/checkbox1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:button="@drawable/custom_checkbox" />

            <CheckBox
                android:id="@+id/checkbox2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:button="@drawable/custom_checkbox2" />

            <CheckBox
                android:id="@+id/checkbox3"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:button="@drawable/custom_checkbox3" />

            <CheckBox
                android:id="@+id/checkboxHomes"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:button="@drawable/custom_checkboxhouses" />

            <CheckBox
                android:id="@+id/checkboxRooms"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:button="@drawable/custom_checkboxrooms" />

        </LinearLayout>

我试图删除布局权重,但 LinearLayout 似乎以某种方式忽略了它并尝试裁剪布局中的最后一个元素。

首先,如果你使用LinearLayout的权重,你设置的权重应该有children android:layout_width="0dp"(或 android:layout_widthLinearLayout 的方向是垂直时)。

Here你有一个解释

第二种情况是您没有为最后一个复选框设置权重:)