2012-04-14 91 views
0

我更改了Android 2.3.4复选框的位图,并且想要设置位图的大小来缩放它们。我改变了这样的复选框:如何更改android复选框的按钮大小?

<CheckBox 
    android:id="@+id/cb1" 
    android:button="@drawable/checkbox" 
    android:layout_alignParentLeft="true" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="Sort: 1" /> 

与匹配的XML绘制

<?xml version="1.0" encoding="utf-8"?> 

<selector xmlns:android="http://schemas.android.com/apk/res/android"> 
    <item android:state_checked="true" android:state_focused="true" android:drawable="@drawable/checkbox_on_background_focus_yellow"/> 
    <item android:state_checked="false" android:state_focused="true" android:drawable="@drawable/checkbox_off_background_focus_yellow"/> 
    <item android:state_checked="false" android:drawable="@drawable/checkbox_off_background" /> 
    <item android:state_checked="true" android:drawable="@drawable/checkbox_on_background" /> 
</selector> 

我怎样才能设置一个DIP/DP值来改变复选框的位图的大小?

回答

2

我通过使位图大小合适来解决这个问题。我现在无法缩放它,但我在具有不同dpi设置的多个设备上测试过,看起来很好。目前。

0

只需定义相关的Drawables并将它们设置为您的复选框属性。

android:background="@drawable/my_background" 
+0

我不知道你的意思,你能不能更精确一点? – HardCoder 2012-04-14 21:42:06

11

,你可以对我做的图像设置为复选框的大小其实是什么把

android:button="@null" 
android:background="@drawable/checkbox" <!-- your custom selector --> 

有了这个,您的自定义图像复选框(在这两个州,选中和未选中)将始终配合到你的复选框的大小。