views:

533

answers:

2

Greetings,

I'm trying to create a single-choice android control, in a horizontal layout, by making use of the RadioGroup behaviour. I can assign the drawable just fine, but i would like to position the label of each RadioButton inside the drawable, is this possible using the standard APIs?

<RadioGroup 
    android:id="@+id/switchcontainer" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"
    android:orientation="horizontal"
    android:checkedButton="@+id/RadioButton02"
    android:padding="3dip">             

    <RadioButton 
        android:text="id RadioButton02" 
        android:id="@+id/RadioButton02" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content"
        android:button="@drawable/radio_button"
        android:paddingRight="2dip" />

    <RadioButton 
        android:text="@+id/RadioButton03" 
        android:id="@+id/RadioButton03" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content"
        android:button="@drawable/radio_button"
        android:paddingRight="2dip" />> 

</RadioGroup>
A: 

I'm not sure about with the RadioGroup; however, it should be possible to accomplish this with a ListView.

Set the ListView choiceMode to singleChoice.

Provide an ArrayAdapter or SimpleAdapter with a custom layout file for the row. This allows you to configure the position of the label.

For a quick intro to ListView's, see Hello ListView

Mayra
I'm sorry, i forgot to mention that i wanted a horizontal layout.Just edited.
monxalo
A: 

Okay, i found a way.

Just use @null in the attribute button, and move the drawable reference to the attribute background like this:

<RadioGroup 
    android:id="@+id/switchcontainer" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"
    android:orientation="horizontal"
    android:checkedButton="@+id/RadioButton02">             

    <RadioButton 
        android:text="id RadioButton02" 
        android:id="@+id/RadioButton02" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content"
        android:background="@drawable/radio_button"
        android:button="@null"/>

    <RadioButton 
        android:text="@+id/RadioButton03" 
        android:id="@+id/RadioButton03" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content"
        android:background="@drawable/radio_button"
        android:button="@null"/>

</RadioGroup>
monxalo