2016-04-15 67 views
0

我試圖通過使用png文件更改複選框中的按鈕,但圖像太大並且使按鈕太大。如何在複選框中更改按鈕的大小

我想將Button的大小更改爲20dp。 然後我在CheckBox中設置了layout_width和layout_height,但它沒有解決問題。

你能教我如何改變尺寸嗎?

<CheckBox 
    android:layout_width="20dp" 
    android:layout_height="20dp" 
    android:text="New CheckBox" 
    android:layout_margin="5dp" 
    android:button="@drawable/my_check_box" 
    android:layout_weight="1" /> 

my_check_box.xml

<?xml version="1.0" encoding="utf-8"?> 
<selector xmlns:android="http://schemas.android.com/apk/res/android"> 
    <item android:state_checked="false" 
     android:drawable="@drawable/checkbox_normal" /> 
    <item android:state_checked="true" 
     android:drawable="@drawable/checkbox_selected" /> 
</selector> 
+0

只是擡起頭來,不要按鈕像圖像一樣縮放。 – zgc7009

回答

0

您需要設置相關的繪製它

<CheckBox 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:text="new checkbox" 
android:background="@drawable/my_checkbox_background" 
android:button="@drawable/my_checkbox" /> 

這個環節有很好的例子 Custom Checkbox

+0

該網站很有幫助。謝謝。 –