如何在Android中调整位图图像的大小

Pro*_*Rev 0 java android textview android-bitmap

<?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>  
Run Code Online (Sandbox Code Playgroud)

这就是我所说的:

TextView aboutBags = new TextView( mContext );
aboutBags.setText("Compose");
aboutBags.setTextAppearance( R.style.RevStyleHelpAbout );
aboutBags.setBackgroundResource( R.drawable.rev_item_h_border_left );  
Run Code Online (Sandbox Code Playgroud)

我已经尝试android:width="22dp" android:height="22dp"过遍及XML的border属性,但是图像的大小没有调整。

如何调整位图图像的大小?

Vielen dank im voraus。

Ani*_*tra 5

使用位图可能会帮助您。像这样使用:

Bitmap nameYourBitmap;

Bitmap resized = Bitmap.createScaledBitmap(nameYourBitmap, newWidth, newHeight, true);
Run Code Online (Sandbox Code Playgroud)

您也可以这样:

resized = Bitmap.createScaledBitmap(nameYourBitmap,(int)(nameYourBitmap.getWidth()*0.8), (int)(nameYourBitmap.getHeight()*0.8), true);
Run Code Online (Sandbox Code Playgroud)

请参考:如何在Android中调整图片大小?

对于XML,比例属性是为ScaleDrawables定义的,它们可以缩放另一个可绘制对象。请访问此开发者网站:https : //developer.android.com/guide/topics/resources/drawable-resource.html#Scale