0

Always radio-buttons have to be set vertically or horizontally, but I want to make them feeding the layout from left to right and then from top to bottom.

Example:

Instead of 5 horizontal buttons or 5 vertical buttons, I want 3 buttons on the first line and 2 buttons on the second line.

I'm looking for a solution using preferably only the xml file.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Antonin GAVREL
  • 9,682
  • 8
  • 54
  • 81

1 Answers1

0

Here you have an example, you have to put your strings in each checkbox

   <LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="5dp"
    android:orientation="horizontal" >

    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:orientation="vertical" >

        <CheckBox
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:button="@null"
            android:drawableLeft="@drawable/your_drawable"
            android:drawablePadding="10dp"
            android:paddingLeft="15dp" />

        <CheckBox
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:button="@null"
            android:drawableLeft="@drawable/your_drawable"
            android:drawablePadding="10dp"
            android:paddingLeft="15dp" />

        <CheckBox
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:button="@null"
            android:drawableLeft="@drawable/your_drawable"
            android:drawablePadding="10dp"
            android:paddingLeft="15dp" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:orientation="vertical" >

        <CheckBox
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:button="@null"
            android:drawableLeft="@drawable/your_drawable"
            android:drawablePadding="10dp"
            android:paddingLeft="15dp" />

        <CheckBox
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:button="@null"
            android:drawableLeft="@drawable/your_drawable"
            android:drawablePadding="10dp"
            android:paddingLeft="15dp" />

        <CheckBox
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:button="@null"
            android:drawableLeft="@drawable/your_drawable"
            android:drawablePadding="10dp"
            android:paddingLeft="15dp" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:orientation="vertical" >

        <CheckBox
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:button="@null"
            android:drawableLeft="@drawable/your_drawable"
            android:drawablePadding="10dp"
            android:paddingLeft="15dp" />

        <CheckBox
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:button="@null"
            android:drawableLeft="@drawable/your_drawable"
            android:drawablePadding="10dp"
            android:paddingLeft="15dp" />

        <CheckBox
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:button="@null"
            android:drawableLeft="@drawable/your_drawable"
            android:drawablePadding="10dp"
            android:paddingLeft="15dp" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:orientation="vertical" >

        <CheckBox

            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:button="@null"
            android:drawableLeft="@drawable/your_drawable"
            android:drawablePadding="10dp"
            android:paddingLeft="15dp" />

        <CheckBox
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:button="@null"
            android:drawableLeft="@drawable/your_drawable"
            android:drawablePadding="10dp"
            android:paddingLeft="15dp"/>
     </LinearLayout>
  </LinearLayout>
JpCrow
  • 4,881
  • 4
  • 32
  • 46
  • but it should unchecked the previous checked item when it is selected. Here you have many checkbox so checking one box will not uncheck another. That is why I am talking about radio-button specifically. – Antonin GAVREL Apr 04 '14 at 01:35
  • Check out this post http://stackoverflow.com/questions/2381560/how-to-group-a-3x3-grid-of-radio-buttons – JpCrow Apr 04 '14 at 02:12
  • I read this one but I'm doing this inside a fragment which means I can't extend TableLayout as I am already extending Fragment. – Antonin GAVREL Apr 04 '14 at 02:57