Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/228.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 自定义复选框的大小是否可绘制?_Android_Android Layout_Android Xml - Fatal编程技术网

Android 自定义复选框的大小是否可绘制?

Android 自定义复选框的大小是否可绘制?,android,android-layout,android-xml,Android,Android Layout,Android Xml,我创建了一个可绘制的自定义复选框: <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_checked="false" android:drawable="@drawable/ic_checkbox_unchecked" /> <item android:state_chec

我创建了一个可绘制的自定义复选框:

<selector  xmlns:android="http://schemas.android.com/apk/res/android">
    <item
        android:state_checked="false"
        android:drawable="@drawable/ic_checkbox_unchecked" />
    <item
        android:state_checked="true"
        android:drawable="@drawable/ic_checkbox_checked" />
    <item
        android:drawable="@drawable/ic_checkbox_unchecked" />
</selector>

我是这样使用的:

<CheckBox
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentEnd="true"
    android:layout_centerVertical="true"
    android:button="@drawable/checkbox"
    />

我创建了两个可绘制图像(一个用于未选中,一个用于已选中),每个尺寸一个(
xxxhdpi
xxhdpi
,等等)

但是,我的复选框显示如下:

<CheckBox
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentEnd="true"
    android:layout_centerVertical="true"
    android:button="@drawable/checkbox"
    />


为什么它会这么大?如何将其缩小到20x20dp?

而不是
wrapcontent
试试看

<CheckBox
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"
android:button="@drawable/checkbox"
/>

<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"
android:button="@drawable/checkbox"
android:scaleX="0.40"
android:scaleY="0.40"
/>


更改比例值,直到达到所需的
大小

您可以使用xml创建此类复选框,并获得所需的结果

将另一个布局文件名设为
ic\u checkbox\u未选中
,并将此文件设置为可绘制而不是图像

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" >
<corners
android:topLeftRadius="0dp"
android:topRightRadius="0dp"
android:bottomLeftRadius="0dp"
android:bottomRightRadius="0dp"
/>
<solid
android:color="#FFFFFC"
/>

<size
android:width="25dp"
android:height="25dp"
/>
<stroke
android:width="3dp"
android:color="#236C87"
/>

您可以使用
标记更改的宽度和高度。
您还可以使用
标记来更改边框宽度。

固定复选框的高度和宽度。取消选中代码ic\U复选框。@Uit14bs
ic\U复选框未选中
ic\U复选框未选中
是图像。您正在使用ic\U复选框未选中其大小。您正在使用的“包裹内容大小”复选框可能是您的图像可绘制的大小很大,这就是为什么显示大复选框复选框被切断(现在只有一条垂直线):@user5495265或尝试缩放它,请选中编辑again@user5495265我希望现在一切正常。但这不会给我20x20dp。@user5495265这只是一个示例,请尝试减小比例值以获得所需的大小