少し詰まったので自分用メモ
selectorのサイズ指定
drawable内のxmlファイルでselector内の画像サイズを指定するには、<item>
内に<layer-list>
, <item>
を作成してwidth, height, drawableを指定。
<selector>
直下の<item>
にwidth, heightを指定しても私の環境では反映されなかったので注意
(drawableは反映された)。
smple.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!--ここでwidth, heightを指定しても反映されない-->
<item android:state_checked="false">
<layer-list>
<!--ここでwidth, heightを指定-->
<item
android:width="20dp"
android:height="10dp"
android:drawable="@drawable/icon_off"/>
</layer-list>
</item>
<item android:state_checked="true">
<layer-list>
<item
android:width="20dp"
android:height="10dp"
android:drawable="@drawable/icon_on"/>
</layer-list>
</item>
</selector>
以上になるが、selector以外の場合も補足(drawable,shape)。
drawableのサイズ指定
sample.xml
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<!--ここでwidth, heightを指定-->
<item
android:width="20dp"
android:height="10dp"
android:drawable="@drawable/icon"/>
</layer-list>
shapeのサイズ指定
sample.xml
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<solid android:color="@color/color"/>
<!--ここでwidth, heightを指定-->
<size
android:width="20dp"
android:height="10dp"/>
</shape>