如何调整 XML 中选择器项目的大小:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="false" android:drawable="@drawable/check_box_2" />
<item android:state_checked="true" android:drawable="@drawable/check_box_1" />
<item android:drawable="@drawable/check_box_2" /> <!-- default state -->
</selector>
我的 XML 是:
<CheckBox
android:text="llllll"
android:button="@drawable/custom_checkbox"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
最佳答案
您可以通过以下方式更改它:
<item>
<shape android:shape="rectangle">
<size android:width="30" android:height="40"/>
<solid android:color="#000000" />
</shape>
</item>
从 API 级别 23 及更高版本开始,您实际上可以设置项目的宽度和高度
<item
android:drawable="@drawable/splash_logo"
android:height="100dp"
android:width="100dp" />
注意:它是 android:width
而不是 android:layout_width
编辑
但是,还有另一种方法可以实现相同的目的,即相应地附加 xml
:
Checked.xml
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android=http://schemas.android.com/apk/res/android
android:shape="rectangle">
<gradient
android:startColor="#ffff0000"
android:endColor="#ff000000"
android:angle="270" />
<stroke
android:width="4px"
android:color="#ffc0c0c0" />
<size
android:height="20dp"
android:width="20dp" />
</shape>
然后将其附加为:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="false" android:drawable="@xml/Checked" />
<item android:state_checked="true" android:drawable="@drawable/check_box_1" />
<item android:drawable="@drawable/check_box_2" /> <!-- default state -->
</selector>
请注意您的 xml
文件中的已检查。您可以通过编辑它来实现任何目的(相应地)
关于java - 如何调整项目选择器 xml 中的图像大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45799690/