1

I have some images in my App and want to use the same reference for multiple screens, is it possible to use the scale tag in xml to re-size the image and use it with different resolutions? when i tried it the picture disappeared!

For example i did this :

First of all i created new XML file add_more_items_scaled

   <?xml version="1.0" encoding="utf-8"?>
<scale xmlns:android="http://schemas.android.com/apk/res/android" 
    android:drawable="@drawable/add_more_items"
    android:scaleWidth="75%"
    android:scaleHeight="75%">


</scale>

then created another XML file add_more_items_button

  <?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
    <item android:drawable="@drawable/button_pressed"
        android:state_pressed="true"></item>
    <item android:drawable="@drawable/add_more_items_scaled"
        android:state_focused="true"></item>
    <item android:drawable="@drawable/add_more_items_scaled"></item>

and when i set the background of the button @android:background:"@drawable/add_more_items_button" it gives me an empty button

So, any suggestions?

Borzstag
  • 43
  • 5

1 Answers1

0

You cant apply scale tag to the Image, as it purpose it to scale drawables not images.

As the documentation for it says:

A drawable defined in XML that changes the size of another drawable based on its current level.

solution:

You can put a weight on your button and instead of using Button you can use ImageButton and set its scaleType to fitXY to fill the bound of it.

Rod_Algonquin
  • 26,074
  • 6
  • 52
  • 63