Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to center text into radio button

I have customized the original radiobutton with a specific background and by removing the button :

styles.xml :

<style name="echelle_relecture">
    <item name="android:background">@drawable/btn_relecture_echelle</item>
    <item name="android:button">@null</item>
    <item name="android:layout_gravity">center_horizontal</item>
</style>

radio.xml :

<RadioGroup android:layout_height="wrap_content" android:id="@+id/radioGroup1" android:layout_width="fill_parent" android:orientation="horizontal" android:layout_marginTop="10dp">
        <RadioButton style="@style/echelle_relecture" android:text="@string/day" android:id="@+id/jour" android:checked="true"></RadioButton>
        <RadioButton style="@style/echelle_relecture" android:text="@string/hour" android:id="@+id/hour" android:button="@null"></RadioButton>
        <RadioButton style="@style/echelle_relecture" android:text="@string/min" android:id="@+id/mins" android:button="@null" android:enabled="false"></RadioButton>
</RadioGroup>

Despite the "center_horizontal" parameter i can't get the text centered inside the button. How can i do that ?

like image 621
grunk Avatar asked Aug 04 '11 11:08

grunk


3 Answers

use this

android:gravity="center"
like image 146
ilango j Avatar answered Oct 24 '22 12:10

ilango j


You should use gravity, not layout_gravity to centralize text inside RadioButton.

like image 26
inazaruk Avatar answered Oct 24 '22 14:10

inazaruk


<RadioButton
    ...
    android:textAlignment="center"
    ... />
like image 40
Wenxiu Jin Avatar answered Oct 24 '22 14:10

Wenxiu Jin