Android 单选按钮自定义方向
我有一个方向水平的Android 单选按钮自定义方向,android,Android,我有一个方向水平的RadioGroup。我想在同一行中显示3个单选按钮,在另一行中显示最后一个单选按钮bcoz小屏幕手机无法在同一行中显示所有按钮。我希望所有单选按钮都在同一个RadioGroup中。我怎样才能做到呢 请通读这段代码,希望对您有所帮助 试着这样做: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/an
RadioGroup
。我想在同一行中显示3个单选按钮,在另一行中显示最后一个单选按钮bcoz小屏幕手机无法在同一行中显示所有按钮。我希望所有单选按钮都在同一个RadioGroup
中。我怎样才能做到呢
请通读这段代码,希望对您有所帮助
试着这样做:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<RadioGroup
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:weightSum="3"
android:orientation="horizontal">
<RadioButton
android:id="@+id/rb_oval"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:buttonTint="@color/colorGreen"
android:checked="false"
android:layout_weight="1"
android:text="Oval" />
<RadioButton
android:id="@+id/rb_circle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:buttonTint="@color/colorGreen"
android:layout_weight="1"
android:checked="false"
android:text="Circle" />
<RadioButton
android:id="@+id/rb_oblong"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:buttonTint="@color/colorGreen"
android:checked="false"
android:text="Oblong" />
</LinearLayout>
<RadioButton
android:id="@+id/rb_rectangle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:buttonTint="@color/colorGreen"
android:checked="false"
android:text="Square/Rectangle" />
</RadioGroup>
</LinearLayout>
使用此库:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<RadioGroup
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<RadioButton
android:id="@+id/rb_oval"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Oval"
android:checked="false"
android:buttonTint="@color/colorPrimary"/>
<RadioButton
android:id="@+id/rb_circle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Circle"
android:checked="false"
android:buttonTint="@color/colorPrimaryDark"/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<RadioButton
android:id="@+id/rb_oblong"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Oblong"
android:checked="false"
android:buttonTint="@color/colorAccent"/>
<RadioButton
android:id="@+id/rb_rectangle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Square/Rectangle"
android:checked="false"
android:buttonTint="@color/colorPrimaryDark"></RadioButton>
</LinearLayout>
</RadioGroup>
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<RadioGroup
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:weightSum="3"
android:orientation="horizontal">
<RadioButton
android:id="@+id/rb_oval"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:buttonTint="@color/colorGreen"
android:checked="false"
android:layout_weight="1"
android:text="Oval" />
<RadioButton
android:id="@+id/rb_circle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:buttonTint="@color/colorGreen"
android:layout_weight="1"
android:checked="false"
android:text="Circle" />
<RadioButton
android:id="@+id/rb_oblong"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:buttonTint="@color/colorGreen"
android:checked="false"
android:text="Oblong" />
</LinearLayout>
<RadioButton
android:id="@+id/rb_rectangle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:buttonTint="@color/colorGreen"
android:checked="false"
android:text="Square/Rectangle" />
</RadioGroup>
</LinearLayout>