2012-04-14 70 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 --> 

有了這個,您的自定義圖像複選框(在這兩個州,選中和未選中)將始終配合到你的複選框的大小。