Program-Me-Rev
Program-Me-Rev

Reputation: 6624

How to resize a Bitmap image in Android

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"
    android:paddingLeft="32dp"
    android:paddingTop="10dp"
    android:paddingRight="0dp"
    android:paddingBottom="10dp">
    <item android:bottom="3dp">
        <bitmap
            android:gravity="center_vertical|left"
            android:src="@drawable/ic_publish_black_24dp" />
        <shape android:shape="rectangle">
            <stroke
                android:width="0dp"
                android:color="#37474f" />
        </shape>
    </item>
</layer-list>  

This is how I call it:

TextView aboutBags = new TextView( mContext );
aboutBags.setText("Compose");
aboutBags.setTextAppearance( R.style.RevStyleHelpAbout );
aboutBags.setBackgroundResource( R.drawable.rev_item_h_border_left );  

I've tried border attributes android:width="22dp" android:height="22dp" all over the XML, but the image doesn't get resized.

How can I resize the bitmap image?

Vielen dank im voraus.

Upvotes: 2

Views: 14702

Answers (1)

Animesh Patra
Animesh Patra

Reputation: 852

Using Bitmap may help you. Use like this:

Bitmap nameYourBitmap;

Bitmap resized = Bitmap.createScaledBitmap(nameYourBitmap, newWidth, newHeight, true);

You can also do like this:

resized = Bitmap.createScaledBitmap(nameYourBitmap,(int)(nameYourBitmap.getWidth()*0.8), (int)(nameYourBitmap.getHeight()*0.8), true);

Refer to this: How to resize Image in Android?

For XML, the scale attributes are defined for ScaleDrawables, and they can scale another drawable. Please refer to this developer site: https://developer.android.com/guide/topics/resources/drawable-resource.html#Scale

Upvotes: 7

Related Questions