Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Radiobutton with text above button

I am new to android and I need to add radio buttons on my activity, but i need to place the text on the to of the bullet button.

Any help please. I found the following, though I dont understand what the @drawable/main_selector and @style/TabStyle.

Radiobutton with text on top

Can anyone give me a 101 guide.

UPDATE

I used the following according to some suggestion but didnt work:

<RadioGroup xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<RadioButton
    android:text="something that is on top"
    android:id="@+id/toggle_tab_left"
    android:button="?android:attr/listChoiceIndicatorSingle"        
    style="@null"/>

<RadioButton 
    android:button="?android:attr/listChoiceIndicatorSingle"
    android:text="something that is on top"
    android:id="@+id/toggle_tab_right"
    style="@null"/>
</RadioGroup>

UPDATE 2

I got my solution from Warpzit, but befor i mark the question as answered, can someone help me on the alignment issue below. I will have 5 radio buttons in a row where some of them will have longer text split in 2 lines. when the text fit on the screen, because of landscape, or on tablets then all text should be in one line:

enter image description here

UPDATE 3

... depending on the screen size the text can split into different number of lines. It wont be always standard

enter image description here

like image 839
Yiannis Stavrianos Avatar asked Sep 30 '13 19:09

Yiannis Stavrianos


1 Answers

To complement Warpzit great answer, you should use android:gravity="center_horizontal|bottom" and android:layout_height="match_parent" on the buttons, to align them.

Also there's no need to copy the radio button drawables from AOSP, use ?android:attr/listChoiceIndicatorSingle.

Screenshot

XML Layout

<RadioGroup xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/radioGroup1"
    android:layout_width="400dp"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:padding="20dp" >

    <RadioButton
        android:id="@+id/radio0"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:button="@null"
        android:drawableBottom="?android:attr/listChoiceIndicatorSingle"
        android:gravity="center_horizontal|bottom"
        android:text="RadioButton" />

    <RadioButton
        android:id="@+id/radio1"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:button="@null"
        android:drawableBottom="?android:attr/listChoiceIndicatorSingle"
        android:gravity="center_horizontal|bottom"
        android:text="RadioButton dsfsdfsdfsdfsdf" />

    <RadioButton
        android:id="@+id/radio2"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:button="@null"
        android:drawableBottom="?android:attr/listChoiceIndicatorSingle"
        android:gravity="center_horizontal|bottom"
        android:text="RadioButton fdsfsd fdsfsdf fsfsdfs" />

</RadioGroup>
like image 112
sergio91pt Avatar answered Oct 21 '22 19:10

sergio91pt