繁体   English   中英

如何更改Android复选框的按钮大小?

[英]How to change the size of the button of an android checkbox?

我更改了Android 2.3.4复选框的位图,并希望设置位图的大小以缩放它们。 我这样更改了复选框:

<CheckBox
    android:id="@+id/cb1"
    android:button="@drawable/checkbox"
    android:layout_alignParentLeft="true"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="Sort: 1" />

与匹配的XML drawable

<?xml version="1.0" encoding="utf-8"?>

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_checked="true"  android:state_focused="true"    android:drawable="@drawable/checkbox_on_background_focus_yellow"/>
    <item android:state_checked="false" android:state_focused="true"    android:drawable="@drawable/checkbox_off_background_focus_yellow"/>
    <item android:state_checked="false" android:drawable="@drawable/checkbox_off_background" />
    <item android:state_checked="true"  android:drawable="@drawable/checkbox_on_background" />
</selector>

如何设置dip / dp值来更改复选框的位图大小?

实际上,您可以将图片设置为复选框大小的方法是

android:button="@null"
android:background="@drawable/checkbox" <!-- your custom selector -->

这样,您的自定义复选框图片(在两种状态下均处于选中状态和未选中状态)将始终适合复选框的大小。

我通过使位图的大小正确来解决了这个问题。 我现在无法缩放它,但是我在具有不同dpi设置的多个设备上对其进行了测试,看起来还不错。 目前。

只需定义相关的Drawable并将其设置为您的复选框属性即可。

android:background="@drawable/my_background"

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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