Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scale a drawable resource in XML (Android)

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?

like image 271
Addev Avatar asked Jan 07 '13 11:01

Addev


People also ask

How do you change drawable size on android?

Once you import svg file into Android Studio project, you are going to see <vector> resource then just change the size as you want by width , height attributes. viewportWidth and viewportHeight is to set size for drawing on virtual canvas.

How do you set the content of an Imageview in your XML layout file?

Navigate to the app > res > layout > activity_main. xml and add the below code to that file.

What is drawable resource in android?

A drawable resource is a general concept for a graphic that can be drawn to the screen and which you can retrieve with APIs such as getDrawable(int) or apply to another XML resource with attributes such as android:drawable and android:icon . There are several different types of drawables: Bitmap File.


1 Answers

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" />
like image 65
Usama Saeed US Avatar answered Oct 16 '22 08:10

Usama Saeed US