Android RadioButton 如何让文字在左边,圈圈在右边

本文介绍如何在XML文件中通过设置特定属性使RadioButton的文字显示在左边,而选择框显示在右边。通过使用android:layoutDirection=rtl和android:textDirection=ltr属性,可以实现在宽设为match_parent时,圈圈默认右对齐的效果。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

RadioButton 如何让文字在左边,圈圈在右边

在xml文件中RadioButton控件上添加如下属性:

android:layoutDirection="rtl"
android:textDirection="ltr"

RadioButton添加完上面属性后,当宽设为match_parent,圈圈默认右对齐,代码如下,效果如下图:

<RadioButton
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:drawableLeft="@mipmap/weixinzhifu"
    android:drawablePadding="5dp"
    android:layoutDirection="rtl"
    android:text="微信支付"
    android:textDirection="ltr" />

<RadioButton
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:drawableLeft="@mipmap/zhifubaozhifu"
    android:drawablePadding="5dp"
    android:layoutDirection="rtl"
    android:text="支付宝支付"
    android:textDirection="ltr" />

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值