水平显示复选框

时间:2017-05-14 03:02:27

标签: android

是否可以水平(而不是垂直)显示复选框,类似于单选按钮上显示的选项?在肯定的情况下,如何做到这一点?

谢谢。

约瑟夫

1 个答案:

答案 0 :(得分:1)

是的,将它们包裹在一个线性布局中,给每个人一个layout_weight,然后连续添加你想要的数量......虽然在某个时间点它们会开始“挤压”在一起,你不应该这样做..

<?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">


    <LinearLayout
        android:layout_width="match_parent"
        android:orientation="horizontal"
        android:layout_height="wrap_content">

        <CheckBox
            android:id="@+id/checkBox"
            android:layout_weight="1"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:text="CheckBox" />

        <CheckBox
            android:id="@+id/checkBox2"
            android:layout_weight="1"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:text="CheckBox" />

        //Copy Paste More CheckBoxes...

    </LinearLayout>
</LinearLayout>
相关问题