There are two ways to expand the CheckBox click area

To expand the click area, the first thing that comes to mind is to add a padding, the code is as follows:

<CheckBox
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:padding="10dp"
        android:background="@android:color/holo_blue_dark"
        android:button="@drawable/check_selector"/>

The effect is as follows:


It is found that paddingStart is equivalent to invalid. The reason is that CheckBox inherits CompoundButton, and CompoundButton is caused by the drawing problem of button.

Solution one:

Add a transparent area directly on the four sides of the picture, which is simple and rude.

Solution two:

Set the button to null and the picture to drawable, so paddingStart will take effect

<CheckBox
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:padding="10dp"
        android:background="@android:color/transparent"
        android:button="@null"
        android:drawableStart="@drawable/check_selector"/>


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324950618&siteId=291194637