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

标签 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>  

我是这样调用它的:

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可能会帮助你。像这样使用:

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);

引用:How to resize Image in Android?

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

关于java - 如何在 Android 中调整位图图像的大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45115924/

相关文章:

android - Xamarin PickerRenderer - 获取微调器?

android - 如何在钛合金中向通知添加声音

Android:避免在 TextView 字符串部分换行

android - 每个特定字符的不同颜色

java - Python 脚本不会在本地主机 gae 开发服务器的 urlopen 之后读取()——对等连接重置

java - 使用Java快速计算字符串中单词出现次数的方法

java - RxJava2 在 toList 之后未收到 doOnNext

Android TextView 下划线不起作用

java - 我应该如何修复找不到所需类型的 bean?

java - 如何让 Apple Java Extensions (com.apple.eawt) 在 JDK 7 及更高版本上运行?