gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 17:55:40 27 4
gpt4 key购买 nike

<?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/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com