如何在Android布局中缩小图像大小?

时间:2013-12-10 21:50:58

标签: android image android-layout layout imageview

我有一个想要在Android布局中显示的图像

但我希望它比原始尺寸小一些。

我该怎么做?

如果我指定一些宽度和高度,它会裁剪图像而不是缩小图像

2 个答案:

答案 0 :(得分:1)

使用scaleType属性定义ImageView的缩放比例,例如: :

android:scaleType="fitCenter"

请参阅http://developer.android.com/reference/android/widget/ImageView.ScaleType.html

答案 1 :(得分:0)

您可以使用以下代码示例将图像缩放到80%大小。

int srcWidth = srcBitmap.getWidth();
int srcHeight = srcBitmap.getHeight();
int dstWidth = (int)(srcWidth*0.8f);
int dstHeight = (int)(srcHeight*0.8f);
Bitmap dstBitmap = Bitmap.createScaledBitmap(srcBitmap, dstWidth, dstHeight, true);

根据您需要缩放的百分比更改多重值。

另外,请参阅此链接以获取更多选项。 Scaling bitmap to 80 percent