Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to specify width and height of a drawable item

Tags:

android

layout

Hi is there anyway of providing width and height of a drawable defined in drawable.xml in drawable folder.

Example:

 <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>

I wanted to specify width and height maybe somehow using "scale" tag inside it which i tried but didnt worked. This is my code:

<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>
like image 653
user606669 Avatar asked Sep 23 '11 14:09

user606669


1 Answers

layer-list will help: here change values according to your requirement

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
    <shape>
        <size
            android:width="20dp"
            android:height="20dp" />

        <solid android:color="@android:color/black" />
    </shape>
</item>
<item
    android:width="20dp"
    android:height="20dp"
    android:drawable="@drawable/slider_knob" />

like image 67
Parth Avatar answered Oct 22 '22 11:10

Parth