all*_*oid 1 xml checkbox android android-layout
我正在为CheckBox小部件添加图像(而不是使用选择器在.xml文件中为单击和未单击的默认图像),但是无法将图像调整为较小的尺寸并保留其原始格式尺寸。
如何缩小图像尺寸?
我用来创建CheckBox的代码是
<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" />
Run Code Online (Sandbox Code Playgroud)
将android:button字段设置为null并将复选框设置为复选框的android:background字段
<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" />
Run Code Online (Sandbox Code Playgroud)
将android:button字段设置为 null 并将复选框状态设置为复选框的android:background字段。
然后你的代码将变成:
<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" />
Run Code Online (Sandbox Code Playgroud)