Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Text below RadioButtons

I need your help to solve my layout problem.. I have 4 RadioButtons, they appear as usual in this scheme:

O text1   O text2   O text3   O text4

where O is the button.. I would know if it's possible to change this layout in this way:

  O       O       O       O

text1  text2  text3  text4

like image 455
Erenwoid Avatar asked Jul 22 '11 00:07

Erenwoid


2 Answers

This is the solution to set the Text below RadioButtons:

This code android:drawablePadding="-20dp" is not needed.

You add your own selector drawable here: android:drawableTop="@drawable/your_Image_Here".

<RadioGroup
        android:id="@+id/RadioGroup1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true"
        android:orientation="horizontal" >

        <RadioButton
            android:id="@+id/Icon1"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:background="@android:color/transparent"
            android:button="@android:color/transparent"
            android:checked="true"
            android:drawablePadding="-20dp"
            android:drawableTop="@drawable/your_Image_Here"
            android:gravity="center"
            android:text="@string/your_Text_Here"
            android:textColor="@color/icons_color" />

        <RadioButton
            android:id="@+id/Icon2"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:background="@android:color/transparent"
            android:button="@android:color/transparent"
            android:drawablePadding="-20dp"
            android:drawableTop="@drawable/your_Image_Here"
            android:gravity="center"
            android:text="@string/your_Text_Here"
            android:textColor="@color/icons_color" />
    </RadioGroup>
like image 196
Abdullah Avatar answered Nov 14 '22 12:11

Abdullah


I don't think the plain RadioButton widget can do that by default. You'll need to do one of a few things to achieve that effect. You can create your own RadioButton view class by combining a RadioButton and a TextView so that you have complete control over where the items are in relation to each other. Or you can skip making it a view and just use two elements in your layout, 1 TextView and one RadioButton(with no text set to it).

like image 37
FoamyGuy Avatar answered Nov 14 '22 10:11

FoamyGuy