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

来源:互联网 发布:会计核算软件包括哪些 编辑:程序博客网 时间:2024/05/01 18:50

        做项目的时候遇到要自定义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>


2 0
原创粉丝点击