[英]How to resize image of checkbox in android?
我正在为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" />
将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" />
要将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" />
@berry:请设置android:button="@null"
并将其设置在您的android:background
。
android:button="@null"
android:background="@drawable/check_box.xml"
当布局的宽度和高度设置为wrap_content时, CheckBox不遵守android:button可绘制对象的大小。 因此,请使用android:background 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.