9

I'm trying to scale a drawable to the double of its original size.I'm trying to use this: Drawable Resouces. My current code is:

Drawable:

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

</scale>

Layout:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/ic_launcher" />

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/scale2" />

</LinearLayout>

But nothing is shown in the second ImageView. How can I fix it?

Ionică Bizău
  • 109,027
  • 88
  • 289
  • 474
Addev
  • 31,819
  • 51
  • 183
  • 302
  • Duplicate here: http://stackoverflow.com/questions/5507539/android-scaledrawable-doesnt-seems-to-work – nmw Jan 07 '13 at 11:54

2 Answers2

13

Once i had this problem i found the solution by using inset instead of scale. Create a new xml drawable file in drawable folder and add you code like this:

<?xml version="1.0" encoding="utf-8"?>
<inset xmlns:android="http://schemas.android.com/apk/res/android"
android:drawable="@drawable/buttonright"
android:insetTop="4dp"
android:insetLeft="4dp"
android:insetRight="4dp"
android:insetBottom="4dp"
/>

use it like this

   <ImageView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/scale" />
Usama Saeed US
  • 984
  • 11
  • 18
6

Drawable

<?xml version="1.0" encoding="utf-8"?>
<scale xmlns:android="http://schemas.android.com/apk/res/android"
    android:drawable="@drawable/logo"
    android:scaleGravity="center_vertical|center_horizontal"
    android:scaleHeight="80%"
    android:scaleWidth="80%" />

layout

   <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/scale" />

try like this or you may check this link.

http://developer.android.com/guide/topics/resources/drawable-resource.html

Janmejoy
  • 2,721
  • 1
  • 20
  • 38