繁体   English   中英

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

[英]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>  

这就是我所说的:

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

我已经在XML上尝试了边框属性android:width="22dp" android:height="22dp" ,但是图像的大小没有调整。

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

Vielen dank im voraus。

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

Bitmap nameYourBitmap;

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

您也可以这样:

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

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM