CheckBox改变大小

来源:互联网 发布:win8网络限速解除 编辑:程序博客网 时间:2024/06/05 18:41

CheckBox设置width和height只能改变控件所占空间的大小,不能改变CheckBox框框的大小,我们只能通过selector改变图片来改变CheckBox框框的大小

1、准备2张图片 你需要的大小,一个选中的,一个未选中的
       
2、checkbox_selector.xml 在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/checkbox_checked" /><!--选中时效果-->  
<item android:state_checked="false"   
android:drawable="@drawable/checkbox_unchecked" /><!--未选中时效果-->  
</selector>


3、styles.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="MyCheckBox" parent="@android:style/Widget.CompoundButton.CheckBox">
<item name="android:button">@drawable/checkbox_selector</item>
</style>
</resources>


4、调用时
<CheckBox
android:id="@+id/checkBox2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="@style/MyCheckBox"/>

0 0