做项目的遇到要自定义RadioButton的样式,在网上搜索了很多例子都没有完美解决,
当android:button=”@null”的是时候但它的位置还在,空出了很大一块,横向排列的时候不是很美观。
试了很多办法终于解决了这个小问题就是把背景也设为”@null” 这样:android:background=”@null” ,
就可以了 它的也就没有了 空出的很大部分也没有了。
显示效果:(比较紧凑了,不会像原来那样每个button间间隔开很多)
[java]
<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>
[/java]