嗨,无论如何提供drawable文件夹中drawable.xml中定义的drawable的宽度和高度.
例:
<selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_pressed="true" android:drawable="@drawable/button_pressed" /> <!-- pressed --> <item android:state_focused="true" android:drawable="@drawable/button_focused" /> <!-- focused --> <item android:drawable="@drawable/button_normal" /> <!-- default --> </selector>
我想指定宽度和高度可能以某种方式在其中使用“scale”标签,我试过但没有工作.这是我的代码:
<selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:drawable="@drawable/icon_ratingstar"> <scale android:scaleWidth="20" android:scaleHeight="20" android:drawable="@drawable/icon_ratingstar" /> </item> </selector>
解决方法
您可以在< item>内指定标记drawable的宽度和高度:
<selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_pressed="true" android:width="100dp" android:height="20dp" android:drawable="@drawable/button_pressed" /> <!-- pressed --> <item android:state_focused="true" android:width="100dp" android:height="20dp" android:drawable="@drawable/button_focused" /> <!-- focused --> <item android:drawable="@drawable/button_normal" /> <!-- default -->