如何在Android中防止图片被缩放

3

我正在编写一款Android应用程序。我从服务器上下载了一张图片,并尝试使用setBackgroundDrawable将其设置为ImageView的背景。

Drawable drawable = Drawable.createFromPath(path)
imageView.setBackgroundDrawable(drawable);

这个方法可以实现,但是图片会被缩小。有没有办法设置一个图像视图的背景而不改变它的大小呢?

编辑: 我通过使用以下代码解决了问题:

File imgFile = new File(path);
Bitmap myBitmap = BitmapFactory.decodeFile(imgFile.getAbsolutePath());
imageView.setImageBitmap(myBitmap);
2个回答

2
imageView.setScaleType (ImageView.ScaleType.MATRIX)

将图像的缩放类型设置为Matrix,绘制时将使用图像矩阵进行缩放。


很遗憾,它不起作用。我通过使用以下代码解决了我的问题: File imgFile = new File(path); Bitmap myBitmap = BitmapFactory.decodeFile(imgFile.getAbsolutePath()); - b.i
没问题。请将您的解决方案发布为答案,以便其他人能够快速了解。 - Mitul Nakum

1
请使用这两个属性:
 android:scaleType
 android:adjustViewBounds

关于它们的学习:ImageView


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接