android CheckBox RadioButton 照片和文字的间距问题
利用自身的定义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>
尽管通过设置paddingLeft在有的系统上能够显示想要的,可是有些则不行
<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()方法设置选中和未选中效果。这样就不存在图标和文本的空隙问题了,问题完美解决。
版权声明:本文博客原创文章,博客,未经同意,不得转载。
android CheckBox RadioButton 照片和文字的间距问题的更多相关文章
- checkbox与文字的间距
1. checkbox在更换了图片后, 与文字的距离有问题, 建议修改background为@null, 去除占据的位置. 2. checkbox的paddingleft可以控制图片和文字的间距.
- android学习日记03--常用控件checkbox/radiobutton
常用控件3.checkbox 复选框,确定是否勾选,点击一下勾选,点击第二下取消,当有一系列备选项时适合用checkbox控件,方便用户提交数据. 贴上例子Activity的java代码 packag ...
- Android checkbox和radiobutton 以及Toast和AlertDialog的使用
package com.example.radiobutton_01; import android.app.Activity; import android.os.Bundle; import an ...
- Android 单选按钮(RadioButton)和复选框(CheckBox)的使用
1.RadioButton (1)介绍 (2)单选按钮点击事件的用法 (3)RadioButton与RadioGroup配合使用实现单选题功能 (4)xml布局及使用 <?xml version ...
- android.widget.RadioButton 单选按钮(转)
大家好,我们今天这一节要介绍的是RadioGroup 的组事件.RadioGroup 可将各自不同的RadioButton ,设限于同一个Radio 按钮组,同一个RadioGroup 组里的按钮,只 ...
- Android 自定义RadioButton实现
由于使用小米系统MIUI运行是RadioButton样式跟google Android API自定义的不一样,则我们可以定义任何想要的东东.没有做不到,只有想不到 Android 自定义RadioBu ...
- Android的TextView在显示文字的时候,如果有段中文有英文,有中文,有中文标点符号,你会发现,当要换行的时候遇到中文标点, 这一行就会空出很多空格出来
一.问题描述: Android的TextView在显示文字的时候,如果有段中文有英文,有中文,有中文标点符号,你会发现,当要换行的时候遇到中文标点, 这一行就会空出很多空格出来.原因是: 1) Tex ...
- Android自定义View 画弧形,文字,并增加动画效果
一个简单的Android自定义View的demo,画弧形,文字,开启一个多线程更新ui界面,在子线程更新ui是不允许的,但是View提供了方法,让我们来了解下吧. 1.封装一个抽象的View类 B ...
- Android 使用Font Awesome 显示文字图标
Android 使用Font Awesome 显示文字图标 简单几步就可以完成 简单的效果图: 1. 创建 assets 文件夹 在Android Studio 上的创建步骤为: 在 src/main ...
随机推荐
- Quasi-Newton Method--LBFGS
Quasi-Newton Method Quasi-Newton Method每一步计算过程中仅涉及到函数值和函数梯度值计算,这样有效避免了Newton Method中涉及到的Hessian矩阵计算问 ...
- core graphics path
当UIKit无法满足画图需求的时候.就须要用到Core Graphics API.当中最普遍的就是path. 一些重要的概念 graphics context 能够理解成canvas.在ios里相应C ...
- 利用jsoup爬取百度网盘资源分享连接(多线程)
突然有一天就想说能不能用某种方法把百度网盘上分享的资源连接抓取下来,于是就动手了.知乎上有人说过最好的方法就是http://pan.baidu.com/wap抓取,一看果然链接后面的uk值是一串数字, ...
- Windows上的的神技
Windows上的的神技 不用借助任何第三方软件,其实Windows也大有可为——比你目前了解得至少要多得多,强大技能快来get起来! 1.文件隐藏谁的电脑里没点小秘密?东藏西藏到最后自己都找不到了有 ...
- C语言程序代写(qq:928900200)
1cs3157 – Advanced ProgrammingSummer 2014, Project 1, 150 pointsJune 17, 2014Follow these step-by-st ...
- uip UDPclient模式通信移植,p本地ort可以是无规
现在移植UDPclient模式,使用广播地址检测. //udp_client.c /********************************************************** ...
- Android项目包装apk和apk反编译,xml反编译
一.项目和一般原则其不足之处包 (1)开发一个简单的项目.当发布了APK档.假设我们不使用签名的方式,直接地bin文件夹中找到*.apk档.非常方便,但是,当我们在使用的用户,可能有其他方案覆盖安装. ...
- MVC快速分页
.NET手记-ASP.NET MVC快速分页的实现 对于Web应用,展示List是很常见的需求,随之而来的常见的分页组件.jQuery有现成的分页组件,网上也有着大量的第三方分页组件,都能够快速实 ...
- 【原创翻译】认识MVC设计模式:web应用开发的基础(实际编码篇)
原文地址:http://www.larryullman.com/2009/10/15/understanding-mvc-part-3/ 全系列INDEX [原创翻译]认识MVC设计模式:web应用开 ...
- 【leetCode百题成就】Gas Station解题报告
题目: There are N gas stations along a circular route, where the amount of gas at station i is gas[i]. ...