DKV
DKV

Reputation: 1767

Make the radio button icon to center

I have 3 RadioButton like below enter image description here

The . text is getting the centre, not the icon. I need both the icon and text to center

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" 
android:layout_height="match_parent">

<RadioGroup
    android:layout_width="match_parent"
    android:orientation="horizontal"
    android:layout_height="wrap_content" >

    <RadioButton
        android:layout_gravity="center"
        android:layout_weight="1"
        android:gravity="center"
        android:text="Test1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />
    <RadioButton
        android:layout_gravity="center"
        android:layout_weight="1"
        android:text="Test2"
        android:gravity="center"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

    <RadioButton
        android:layout_gravity="center"
        android:layout_weight="1"
        android:text="Test3"
        android:gravity="center"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

</RadioGroup>

Upvotes: 0

Views: 217

Answers (1)

user4571931
user4571931

Reputation:

You can try below code

<?xml version="1.0" encoding="utf-8"?>
<RadioGroup xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal">

    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"        
        android:gravity="center"
        android:orientation="horizontal">

        <RadioButton
            android:text="Test1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:gravity="center"
        android:orientation="horizontal">

        <RadioButton
            android:text="Test2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:gravity="center"
        android:orientation="horizontal">

        <RadioButton
            android:text="Test3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />
    </LinearLayout>

</RadioGroup>

Upvotes: 1

Related Questions