3

I have a button on which i put an image

I've been told i need to reduce the size of the image by 30%, so i created a scale drawable and put that in the selector of the button

unfortunately, the image does not display on the button as expected.

here is my code for the button

<Button
    android:id="@+id/btnMain"
    style="@style/buttonMenuAppearance"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:drawableTop="@drawable/selector_ic_main"
    android:text="@string/btnMain" />

my selector

    <selector xmlns:android="http://schemas.android.com/apk/res/android">

    <item android:drawable="@drawable/scaled_ic_main_disabled" android:state_enabled="false"></item>
    <item android:drawable="@drawable/ic_main_pressed" android:state_enabled="true" android:state_pressed="true"></item>
    <item android:drawable="@drawable/ic_main_normal" android:state_enabled="true" android:state_pressed="false"></item>
    <item android:drawable="@drawable/ic_main_normal"></item>

    </selector>

my scaled drawable

<scale xmlns:android="http://schemas.android.com/apk/res/android"
android:drawable="@drawable/ic_main_disabled"
android:scaleGravity="center_vertical|center_horizontal"
android:scaleHeight="30%"
android:scaleWidth="30%" />

the way it looked before the scale : enter image description here

the way it looks after the scale : enter image description here

why isnt my image showing up ?

Lena Bru
  • 13,521
  • 11
  • 61
  • 126

1 Answers1

0

Your "scaled image" is called "scale" not "scaled_ic_main_disabled" so your selector is not displaying anything (I guess you don't have any objects called "scaled_ic_main_disabled")

Change "scaled_ic_main_disabled" to "scale" in your selector.

Jim
  • 10,172
  • 1
  • 27
  • 36
  • the scale you are referring to is this: http://developer.android.com/reference/android/graphics/drawable/ScaleDrawable.html – Lena Bru Feb 05 '14 at 16:44
  • I'm actually referring to the name of the XML element you created, like the example here: http://stackoverflow.com/questions/14195206/scale-a-drawable-resource-in-xml-android – Jim Feb 05 '14 at 16:46
  • it wont let me add that, i don't have any file named scale – Lena Bru Feb 05 '14 at 17:25
  • The code you posted above has xml called "scale" - what is that file called? I assumed you named it that, but maybe it's named properly. As another note - you are making it 30% of the original size, not reducing it 30%. And also only setting it for the disabled state - so I assume the button is disabled and it's not just having a build problem from a missing drawable. – Jim Feb 05 '14 at 17:42
  • it is ok if it is 30% of the original size, i will adjust that when the other problem is fixed. Yes the button is indeed disabled, it is disabled on start of the app, and that's the drawable i wanted to make. it is not missing any drawables – Lena Bru Feb 05 '14 at 19:00
  • so your "scale" xml is in a file called "scaled_ic_main_disabled" and that file is in a drawable folder that is either generic or appropriate for your screen density? And "ic_main_disabled" is also in a drawable folder? – Jim Feb 05 '14 at 20:15
  • there are 3 drawables in drawable-hdpi, drawable-mdpi and drawable-xhdpi called "ic_main_disabled.png" those are the pictures, there is scale drawable in the drawable folder (without appendices) called "scaled_ic_main_disabled.xml" , the selector is also in the drawable folder, the same one "scaled_ic_main_disabled.xml" is in – Lena Bru Feb 05 '14 at 20:56