Android中让RadioButton 文字在左边,选择按钮在右边

 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>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值