Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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>
like image 451
TheRealKingK Avatar asked Aug 09 '12 20:08

TheRealKingK


2 Answers

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"/>
like image 154
J. Beck Avatar answered Oct 13 '22 19:10

J. Beck


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.

like image 32
Joel Sjögren Avatar answered Oct 13 '22 21:10

Joel Sjögren