Android 自定义 RadioButton 去除无谓的背景空白实例

来源:互联网 发布:php cookie 登陆 编辑:程序博客网 时间:2024/04/29 16:22

做项目的遇到要自定义RadioButton的样式,在网上搜索了很多例子都没有完美解决,

当android:button="@null"的是时候但它的位置还在,空出了很大一块,横向排列的时候不是很美观。

试了很多办法终于解决了这个小问题就是把背景也设为"@null"  这样:android:background="@null" ,

就可以了 它的也就没有了 空出的很大部分也没有了。


显示效果:(比较紧凑了,不会像原来那样每个button间间隔开很多)



全部代码:

[html] view plaincopyprint?
  1. <RadioGroup  
  2.                     android:layout_width="match_parent"  
  3.                     android:layout_height="wrap_content"  
  4.                     android:gravity="center"  
  5.                     android:orientation="horizontal"  
  6.                     android:paddingBottom="15dp"  
  7.                     android:paddingTop="15dp" >  
  8.    
  9.                     <TextView  
  10.                         android:layout_width="wrap_content"  
  11.                         android:layout_height="wrap_content"  
  12.                         android:layout_marginRight="5dp"  
  13.                         android:text="保额"  
  14.                         android:textColor="#363636"  
  15.                         android:textSize="18sp" />  
  16.    
  17.                     <RadioButton  
  18.                         android:layout_width="wrap_content"  
  19.                         android:layout_height="wrap_content"  
  20.                         android:layout_marginRight="5dp"  
  21.                         android:background="@null"  
  22.                         android:button="@null"  
  23.                         android:drawableLeft="@drawable/radio_selector"  
  24.                         android:singleLine="true"  
  25.                         android:text="10万"  
  26.                         android:textColor="#2991a5"  
  27.                         android:textSize="18sp" />  
  28.    
  29.                     <RadioButton  
  30.                         android:layout_width="wrap_content"  
  31.                         android:layout_height="wrap_content"  
  32.                         android:layout_marginRight="5dp"  
  33.                         android:background="@null"  
  34.                         android:button="@null"  
  35.                         android:drawableLeft="@drawable/radio_selector"  
  36.                         android:singleLine="true"  
  37.                         android:text="20万"  
  38.                         android:textColor="#2991a5"  
  39.                         android:textSize="18sp" />  
  40.    
  41.                     <RadioButton  
  42.                         android:layout_width="wrap_content"  
  43.                         android:layout_height="wrap_content"  
  44.                         android:layout_marginRight="5dp"  
  45.                         android:background="@null"  
  46.                         android:button="@null"  
  47.                         android:drawableLeft="@drawable/radio_selector"  
  48.                         android:singleLine="true"  
  49.                         android:text="50万"  
  50.                         android:textColor="#2991a5"  
  51.                         android:textSize="18sp" />  
  52.    
  53.                     <RadioButton  
  54.                         android:layout_width="wrap_content"  
  55.                         android:layout_height="wrap_content"  
  56.                         android:layout_marginRight="5dp"  
  57.                         android:background="@null"  
  58.                         android:button="@null"  
  59.                         android:drawableLeft="@drawable/radio_selector"  
  60.                         android:singleLine="true"  
  61.                         android:text="100万"  
  62.                         android:textColor="#2991a5"  
  63.                         android:textSize="18sp" />  
  64.                 </RadioGroup>  
0 0
原创粉丝点击