【问题标题】:How to prevent an image from being resized in Android如何防止在Android中调整图像大小
【发布时间】:2012-03-01 09:19:46
【问题描述】:

我正在编写一个安卓应用程序。我正在从服务器下载图像并尝试使用 setBackgroundDrawable 将其设置为 ImageView 背景。

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

它可以工作,但图像被调整大小(它越来越小)。有谁知道如何在不改变其大小的情况下设置图像视图背景?

编辑: 我通过使用解决了这个问题:

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

【问题讨论】:

    标签: android imageview drawable


    【解决方案1】:
    imageView.setScaleType (ImageView.ScaleType.MATRIX)
    

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

    【讨论】:

    • 不幸的是它不起作用。我通过使用 File imgFile = new File(path); 解决了我的问题位图 myBitmap = BitmapFactory.decodeFile(imgFile.getAbsolutePath());
    • 没问题。请将您的解决方案发布为答案,以便其他人很快得到注意。
    【解决方案2】:

    使用这两个属性:

     android:scaleType
     android:adjustViewBounds
    

    在 : ImageView 中研究它们

    【讨论】:

      猜你喜欢
      • 2018-10-11
      • 1970-01-01
      • 2019-03-14
      • 2019-09-21
      • 1970-01-01
      • 2017-01-13
      • 1970-01-01
      • 2015-08-21
      • 1970-01-01
      相关资源
      最近更新 更多