我正在编写一款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);