0

I want my radio buttons to get a little cozier with each other.

I hoped to put them in a radiogroup, thinking that would automatically provide the "if this one is checked, the other ones automatically uncheck" logic.

But with a radiogroup:

<TableRow
        android:id="@+id/tableRow6"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:padding="5dip">

        <RadioGroup
            android:id="@+id/radioEditList"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"

        <RadioButton
            android:id="@+id/radioAlways"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:checked="false"
            android:text="@string/editlist_radgrp_always" />

        <RadioButton
            android:id="@+id/radioNever"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:checked="true"
            android:text="@string/editlist_radgrp_never" />

        <RadioButton
            android:id="@+id/radioCostChange"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/editlist_radgrp_costchange" />
    </RadioGroup>
</TableRow>

...it looks like this:

enter image description here

Without the RadioGroup:

<TableRow
    android:id="@+id/tableRow6"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:padding="5dip">

    <RadioButton
        android:id="@+id/radioAlways"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:checked="false"
        android:text="@string/editlist_radgrp_always" />

    <RadioButton
        android:id="@+id/radioNever"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:checked="true"
        android:text="@string/editlist_radgrp_never" />

    <RadioButton
        android:id="@+id/radioCostChange"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/editlist_radgrp_costchange" />
</TableRow>

...it looks better:

enter image description here

...but still pitifully, or at least woefully, inadequate.

How do I get thee radio buttons to scrunch up together?

B. Clay Shannon-B. Crow Raven
  • 8,547
  • 144
  • 472
  • 862
  • 1
    I had similar problems with Button's padding, and it turned out the problem was with minWidth, minHeight.. Try overriding minWidth alongwith reducing padding.. – Rajat Singhal May 16 '14 at 19:36

2 Answers2

1

You can try putting it all inside a

LinearLayout 

and specifying weights for each button. Something like this:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >

<TableRow
    android:id="@+id/tableRow6"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_weight="3"
    android:padding="5dip" >

    <RadioButton
        android:id="@+id/radioAlways"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:checked="false"
        android:text="always" />

    <RadioButton
        android:id="@+id/radioNever"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:checked="true"
        android:text="never" />

    <RadioButton
        android:id="@+id/radioCostChange"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="costchange" />
</TableRow>

Fareya
  • 1,523
  • 10
  • 11
0

I was able to get it to work this way:

    <RadioGroup
        android:id="@+id/radioEditList"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal">

    <RadioButton
        android:id="@+id/radioAlways"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:checked="false"
        android:text="@string/editlist_radgrp_always" />

    <RadioButton
        android:id="@+id/radioNever"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:checked="true"
        android:text="@string/editlist_radgrp_never" />

    <RadioButton
        android:id="@+id/radioCostChange"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:checked="false"
        android:text="@string/editlist_radgrp_costchange" />

    </RadioGroup>

The difference from my first attempt is there is now a right angle bracket following the radiogroup declaration, and an orientation property set to horizontal. Also, no enclosing TableRow is needed (in fact, it seems to mess things up).

B. Clay Shannon-B. Crow Raven
  • 8,547
  • 144
  • 472
  • 862