简体   繁体   中英

How to resize image of checkbox in android?

I am adding image for a CheckBox widget (that is instead of the default one for both clicked and unclicked ones in .xml file using selector) it's getting added, but the image can't be resized into a smaller one and remains in its original size.

How could I decrease the image size?

The code I used to create the CheckBox is

    <CheckBox
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@color/white"
            android:button="@drawable/check_box"
            android:drawablePadding="20dp"
            android:text="check box text"
            android:textColor="@color/labelColor" />

Set the android:button field to null and to set the checkbox as the android:background field of the checkbox

    <CheckBox    
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:button="@null"
            android:drawablePadding="20dp"
            android:text="check box text"
            android:background="@drawable/check_box" />

To set the android:button field to null and to set the checkbox states as the android:background field of the checkbox.

Your code would then become:

<CheckBox
android:id="@+id/cb"
android:layout_width="wrap_content"
android:layout_height="wrap_content" 
android:button="@null"
android:background="@drawable/check_box"
android:drawablePadding="20dp"
android:text="check box text"
android:textColor="@color/labelColor" />

@berry: Please set android:button="@null" and set this in your android:background .

 android:button="@null"
 android:background="@drawable/check_box.xml"

CheckBox doesn't respect the size of the android:button drawable when the layout width and height are set to wrap_content . So use android:background .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM