Сделайте значок переключателя в центре - PullRequest
0 голосов
/ 11 марта 2019

У меня есть 3 RadioButton, как показано ниже enter image description here

. текст становится центром, а не значком. Мне нужно и значок, и текст для центрирования

<?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>

1 Ответ

1 голос
/ 11 марта 2019

Вы можете попробовать ниже код

<?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>
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...