TheRealKingK
TheRealKingK

Reputation: 839

Have horizontal RadioButtons wrap if too long for screen

So I have the following radiobuttons. I want to have them display like this:

enter image description here

However this occurs:

radiogroup problem

How I can get it to display like above?
I can move in the GUI editor in Eclipse it but it removes the RadioButton from the RadioGroup!
Within the group, it ignores all other layout parameters.

<RadioGroup
    android:id="@+id/radioGroup1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_below="@+id/timeBar"
    android:layout_marginTop="43dp"
    android:orientation="horizontal" >

    <RadioButton
        android:id="@+id/privRadio0"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Everyone" />

    <RadioButton
    android:id="@+id/privRadio1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:checked="true"
    android:text="FriendOfFriends" />


 <RadioButton
    android:id="@+id/privRadio2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Friends" />
</RadioGroup>

Upvotes: 18

Views: 4255

Answers (2)

J. Beck
J. Beck

Reputation: 746

You can simply copy this class:

https://github.com/jevonbeck/AbstractMachine/blob/jevon_dev/app/src/main/java/org/ricts/abstractmachine/ui/utils/MultiLineRadioGroup.java

into an appropriate package in your project and instantiate in XML like so:

<view
    class="mypackage.packagepath.MultiLineRadioGroup"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"/>

Upvotes: 12

Joel Sj&#246;gren
Joel Sj&#246;gren

Reputation: 2090

What you are asking for is a FlowLayout. Such a layout has the benefit of only wrapping when it's needed, as opposed to 0gravity's more "static" solution.

Upvotes: 1

Related Questions