Radiobutton样式
2015-06-12 10:04
686 查看
RadioButton布局脚本:
其中 android:button="@null" 这句很重要,用来消除掉RadioButton标配的圆圈单选按钮!
而 android:drawablePadding="-20dp" 是用来去掉标配分给RadioButton文本的空位,当图片素材画在了drawableTop上面时,对应的文本会出现在下方,如果不需要填入文本,就用这行代码去掉空位;如果选择画在drawableLeft的话,就不需要这一行。
具体来说分两种情况,一种是API17(4.2.2)中的表现:
另外一种是API14(4.0)以及它之下的各版本(如API8)中的表现:
上面API14和API8的效果是一样的,跟API17对比很明显,就是图片的左边多了一个空位!!这个位置无论怎么调padding、margin之类的参数都无法完全消除掉,很恶心。
至于API17-API14之间到底是哪个系统版本成了分水岭,这个就不得而知了,笔主这边编译环境没有安装更多的版本了,也懒得去研究。
上面这个问题找了好久都没找到原因,甚至于笔主都漫无目的的百度搜索有木有针对不同系统版本使用不同布局文件的方法了...
理所当然的一个但是,笔主本着不依不饶的顽强精神再次检查RadioButton布局属性参数,幸运女神终于降临了,笔主发现一个隐藏已久的陷阱: background !! 这个属性在API17的时候是空的,但是 在API14以下竟然默认配置成了 @android:drawable/btn_radio_label_background !!!既然发现了问题,笔主就二话不说直接填上伟大的 @null ,F5刷新一下屏幕..果不其然,一切又回归自然了!
(左右那俩二货没有弄 background,所以还是那副鸟样 )
处理后的RadioButton布局代码是:
RadioGroup开始的整体代码是:(上面的RadioButton参数被我放到了style文件里面)
选择的时候高亮状态,需要设置相应的selector处理图片素材,这里就不详细说明了。
至此,RadioButton已经能够透明的代替ImageButton了,向下兼容至API8,并带入自动标记高亮单项选择功能,做导航的话应该比单纯的ImageButton更具优势
转自:http://www.cnblogs.com/wavky/p/RadioButton_InsteadOf_ImageButton.html?utm_source=tuicool
<RadioButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:button="@null" android:drawablePadding="-20dp" android:drawableTop="@drawable/cat" />
其中 android:button="@null" 这句很重要,用来消除掉RadioButton标配的圆圈单选按钮!
而 android:drawablePadding="-20dp" 是用来去掉标配分给RadioButton文本的空位,当图片素材画在了drawableTop上面时,对应的文本会出现在下方,如果不需要填入文本,就用这行代码去掉空位;如果选择画在drawableLeft的话,就不需要这一行。
具体来说分两种情况,一种是API17(4.2.2)中的表现:
另外一种是API14(4.0)以及它之下的各版本(如API8)中的表现:
上面API14和API8的效果是一样的,跟API17对比很明显,就是图片的左边多了一个空位!!这个位置无论怎么调padding、margin之类的参数都无法完全消除掉,很恶心。
至于API17-API14之间到底是哪个系统版本成了分水岭,这个就不得而知了,笔主这边编译环境没有安装更多的版本了,也懒得去研究。
上面这个问题找了好久都没找到原因,甚至于笔主都漫无目的的百度搜索有木有针对不同系统版本使用不同布局文件的方法了...
理所当然的一个但是,笔主本着不依不饶的顽强精神再次检查RadioButton布局属性参数,幸运女神终于降临了,笔主发现一个隐藏已久的陷阱: background !! 这个属性在API17的时候是空的,但是 在API14以下竟然默认配置成了 @android:drawable/btn_radio_label_background !!!既然发现了问题,笔主就二话不说直接填上伟大的 @null ,F5刷新一下屏幕..果不其然,一切又回归自然了!
(左右那俩二货没有弄 background,所以还是那副鸟样 )
处理后的RadioButton布局代码是:
<RadioButton android:layout_width="0dp" android:layout_height="wrap_content" android:layout_gravity="center" android:layout_weight="1" android:background="@null" android:button="@null" android:drawablePadding="-20dp" android:drawableTop="@drawable/cat" />
RadioGroup开始的整体代码是:(上面的RadioButton参数被我放到了style文件里面)
<RadioGroup android:id="@+id/radioGroup1" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="center" android:layout_marginTop="50dp" android:orientation="horizontal" > <RadioButton style="@style/radioBut" /> <RadioButton style="@style/radioBut" /> <RadioButton style="@style/radioBut" /> </RadioGroup>
选择的时候高亮状态,需要设置相应的selector处理图片素材,这里就不详细说明了。
至此,RadioButton已经能够透明的代替ImageButton了,向下兼容至API8,并带入自动标记高亮单项选择功能,做导航的话应该比单纯的ImageButton更具优势
转自:http://www.cnblogs.com/wavky/p/RadioButton_InsteadOf_ImageButton.html?utm_source=tuicool
相关文章推荐
- Sass浅谈
- 用CSS如何实现单行图片与文字垂直居中
- 纯CSS实现图片
- 巧用CSS3 :target 伪类制作Dropdown下拉菜单(无JS)
- CSS禅意花园——CSS设计的绝美境界
- ActionBar 样式详解 -- 样式 主题 简介 Actionbar 的 icon logo 标题 菜单样式修改
- CSS3 选择器
- JS、CSS命名规范
- 用CSS截断字符串
- CSS的盒子模型
- CSS在线学习
- 样式与主题
- css元素居中实现方法
- Windows Phone 三、样式和资源
- TIKZ全局样式设置
- css中div高度自适应
- 网页 css 样式 初始化
- CSS3 transform实现图片投影效果
- css sprite---css精灵网页图片应用处理方式分析
- HTML、CSS部分