android CheckBox RadioButton 图片与文字间距问题
来源:互联网 发布:sql 同表复制数据 编辑:程序博客网 时间:2024/06/10 09:03
在使用自定义的CheckBox 或RadioButton时,自定义的图标和文字在不同的手机上显示的间距不同,有时不太好控制,下面是我自定义的CheckBox:
在Layout下的xml:
<CheckBox android:id="@+id/recharge_activity_cb" style="@style/CustomCheckboxTheme" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="我已经阅读并同意" android:textColor="@color/huoqiuLightblackColor" android:checked="true" />
里面自定义的style,style内容为:
<!-- 自定义CheckBox --> <style name="CustomCheckboxTheme" parent="@android:style/Widget.CompoundButton.CheckBox"> <item name="android:button">@drawable/checkbox_style</item> <item name="android:paddingLeft">@dimen/dp8</item> </style>
其中调用了选中和未选中图片,在drawable下:
<?xml version="1.0" encoding="utf-8"?><selector xmlns:android="http://schemas.android.com/apk/res/android" > <item android:state_checked="true" android:drawable="@drawable/agree"/> <item android:state_checked="false" android:drawable="@drawable/disagree"/> <item android:drawable="@drawable/disagree"/></selector>
<item name="android:paddingLeft">@dimen/dp8</item>
那么问题来了,到底用什么方法可以解决呐?
下面是我的解决方案:使用CheckedTextView控件
<CheckedTextView android:id="@+id/recharge_activity_ctv" android:checkMark="@drawable/checkbox_style" android:layout_width="wrap_content" android:layout_height="wrap_content" android:checked="true" />
<TextView android:id="@+id/buy_write_jine_agree_tv" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="我已经阅读并同意" android:textColor="@color/huoqiuLightblackColor" android:layout_marginLeft="@dimen/dp3" />
其中checkMark就是上面drawable下的那个选中状态xml
android:checkMark="@drawable/checkbox_style"
然后在代码中对CheckedTextView使用isChecked()判断是否选中,使用toggle()方法设置选中和未选中效果,这样就不存在图标和文本的空隙问题了,问题完美解决!
0 1
- android CheckBox RadioButton 图片与文字间距问题
- android CheckBox RadioButton 图片与文字间距问题
- android RadioButton 图片与文字间距问题
- Android 自定义CheckBox RadioButton中的button,且设置与文字的间距
- android CheckBox和右侧文字间距问题
- CheckBox与文字的间距
- CheckBox与文字的间距
- CheckBox与文字的间距
- 如何减少RadioButton与文字的间距?
- Android-CheckBox和RadioButton调整间距(有坑,注意)
- 一行代码搞定checkbox文字和复选框的图片间距问题 rediobutton同理
- android自定义CheckBox和RadioButton中文字和图片之间距离问题解决
- android自定义CheckBox和RadioButton中文字和图片之间距离
- android中checkbox文字和复选框的间距设置问题
- RadioButton间距问题
- RadioButton间距问题
- radiobutton的文本方位及与图片间距设置
- Android 设置RadioButton文字在图片左边
- ant找不到tools.jar问题解决
- POJ 1740
- 中文版iTween帮助文档、参数解析
- C++模板学习 1. 模板的概念。
- 玫瑰
- android CheckBox RadioButton 图片与文字间距问题
- runnable的线程抛出异常无法捕获
- CSS:子元素margin-top影响父元素
- csdn第一天
- 交换机初始化配置
- 关于Eclipse配置tomcat
- FZU 2091 播放器 (栈)
- 调用WindowsAPI 打开一个网页
- 将一个分支上的commit 转移到另一个分支上