RadioButton默认选择框是在左边显示的,文字显示在右边,可是在某些场景下,我们想在右边显示选择框,左边显示文字,这时候就需要我们去设置一些属性了,给RadioButton 添加一下两个属性就可实现这种效果
android:layoutDirection="rtl" android:textDirection="ltr"
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/color_background">
<RadioGroup
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:paddingHorizontal="16dp">
<RadioButton
android:id="@+id/rb_alipay"
android:layout_width="match_parent"
android:layout_height="48dp"
android:checked="true"
android:drawableLeft="@mipmap/ic_launcher"
android:drawablePadding="4dp"
android:layoutDirection="rtl"
android:text="支付宝支付"
android:textColor="#333333"
android:textDirection="ltr"
android:textSize="16sp" />
<RadioButton
android:id="@+id/rb_wxpay"
android:layout_width="match_parent"
android:layout_height="48dp"
android:checked="false"
android:drawableLeft="@mipmap/ic_launcher"
android:drawablePadding="4dp"
android:layoutDirection="rtl"
android:text="微信支付"
android:textColor="#333333"
android:textDirection="ltr"
android:textSize="16sp" />
<RadioButton
android:id="@+id/rb_wopay"
android:layout_width="match_parent"
android:layout_height="48dp"
android:checked="false"
android:drawableLeft="@mipmap/ic_launcher"
android:drawablePadding="4dp"
android:layoutDirection="rtl"
android:text="沃支付"
android:textColor="#333333"
android:textDirection="ltr"
android:textSize="16sp" />
</RadioGroup>
</RelativeLayout>