Radiobuttons in a radioGroup in a multiple rows

时间:2015-07-28 16:16:46

标签: android android-view android-inflate android-radiogroup android-radiobutton

Is it possible to create a RadioGroup that will hold radio buttons by 3 in a row? I've checked the internet for an implementation and I found one, but it was not working. The thing is that I need to add them programatically, and they should be grouped 3 per row.

Can someone tell me how can I populate a radioGroup with RadioButtons so they are aligned 3 per row.

Thanks

2 个答案:

答案 0 :(得分:0)

Radiogroup inherits from LinearLayout.
So, set the RadioGroup orientation attribute to "horizontal"

答案 1 :(得分:0)

Radio Group inherits from the LinearLayout ViewGroup so you can make this possible by setting orientation on the viewgroup android:orientation="horizontal"

  <RadioGroup
    android:orientation="horizontal"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content">
    <RadioButton
        android:text="Radio 1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />
    <RadioButton
        android:text="Radio 2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />
    <RadioButton
        android:text="Radio 3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />
</RadioGroup>