【发布时间】:2017-09-19 10:20:40
【问题描述】:
我在 RadioGroup 中有 4 个 RadioButton,如下所示:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RadioGroup
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RadioButton
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:id="@+id/button1"
android:text="Button 1"/>
<RadioButton
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:id="@+id/button2"
android:text="Button 2"/>
<RadioButton
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:id="@+id/button3"
android:text="Button 3"/>
<RadioButton
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:id="@+id/button4"
android:text="Button 4"/>
</RadioGroup>
</RelativeLayout>
我希望 RadioButton 2 在 RadioButton 1 的右侧,我希望 RadioButton 3 在 RadioButton 1 的下方,并且我希望 RadioButton 4 在 RadioButton 3 的右侧。
普通属性如
android:layout_below=""
和
android:layout_toRightOf""
不适用于单选按钮。如何在此处以 XML 中描述的方式放置 RadioButtons?
【问题讨论】:
-
在下面查看我的答案。我添加了一个带输出的工作代码。希望这会有所帮助
-
如果我的回答似乎有用,请投赞成票。提前致谢
标签: android xml attributes radio-button radio-group