自定义RadioButton样式并去除默认样式位置【Android】

        做项目的时候遇到要自定义RadioButton的样式,在网上搜索了很多例子都没有完美解决,当android:button="@null"的是时候但它的位置还在,空出了很大一块,横向排列的时候不是很美观。试了很多办法终于解决了这个小问题就是把背景也设为"@null"  即:android:background="@null" ,就可以了 ,它的也就没有了 空出的很大部分也没有了。
代码如下:

<RadioGroup
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:gravity="center"
    android:orientation="horizontal"
    android:paddingBottom="15dp"
    android:paddingTop="15dp" >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginRight="5dp"
        android:text="保额"
        android:textColor="#363636"
        android:textSize="18sp" />

    <RadioButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginRight="5dp"
        android:background="@null"
        android:button="@null"
        android:drawableLeft="@drawable/radio_selector"
        android:singleLine="true"
        android:text="10万"
        android:textColor="#2991a5"
        android:textSize="18sp" />

    <RadioButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginRight="5dp"
        android:background="@null"
        android:button="@null"
        android:drawableLeft="@drawable/radio_selector"
        android:singleLine="true"
        android:text="20万"
        android:textColor="#2991a5"
        android:textSize="18sp" />

    <RadioButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginRight="5dp"
        android:background="@null"
        android:button="@null"
        android:drawableLeft="@drawable/radio_selector"
        android:singleLine="true"
        android:text="50万"
        android:textColor="#2991a5"
        android:textSize="18sp" />

    <RadioButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginRight="5dp"
        android:background="@null"
        android:button="@null"
        android:drawableLeft="@drawable/radio_selector"
        android:singleLine="true"
        android:text="100万"
        android:textColor="#2991a5"
        android:textSize="18sp" />

</RadioGroup>


  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值