How can I get my Android radio buttons to use less padding?

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?

Upvotes: 0

Views: 103

Answers (2)

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).

Upvotes: 0

Fareya
Fareya

Reputation: 1563

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>

Upvotes: 1

Related Questions