ImageView显示灰色方块而不是图像

时间:2017-11-30 19:08:44

标签: android imageview android-imageview android-glide

enter image description here

我尝试过几种不同的方法,但是imageview仍然只显示一个灰色方块。我正在测试API 17。

以下是我尝试失败的选项:

  
      
  • 将XML中的ImageView配置为:

  •   
  • 固定宽度和高度; wrap_content的宽度和高度; width to match_parent和height to wrap_content

  •   
  • android:scaleType为“fitXY”和“centerCrop”
  •   
  • android:adjustViewBounds为true |假;
  •   

尝试了图像加载方法:

binding.captcha.setImageBitmap (BitmapFactory.decodeFile (imgFile2.getAbsolutePath ()));

也尝试了这个答案https://stackoverflow.com/a/35830800/1764042

尝试滑行:

    Glide.with(this)
    .load (Uri.fromFile (imgFile2))
    .skipMemoryCache (true)
    .diskCacheStrategy (DiskCacheStrategy.NONE)
    .override (150, 150)
    .centerCrop ()
    .into (binding.captcha);

以下选项是唯一显示图像的选项(在背景中),但是我想知道可能发生的事情阻止我使用默认方法显示图像......

    Drawable drawableImage = new BitmapDrawable(BitmapFactory.decodeFile(imgFile2.getAbsolutePath()));
    binding.captcha.setBackgroundDrawable(drawableImage);
  • 注意:
  • imgFile2不为空,它是从SD卡加载的。
  • imgFile2显示我是否将其用作背景,因此问题不在于文件。
  • 这个问题不是简单地用lib解决的,我已经尝试过Glide了......但是如果你知道我需要做什么才能让它与滑行一起工作......
  • 如果重要的话,imageView就在片段内。

实际xml:

        <ImageView
            android:layout_width="150dp"
            android:layout_height="150dp"
            android:layout_centerHorizontal="true"
            android:id="@+id/captcha"/>

1 个答案:

答案 0 :(得分:1)

对于那些仍然面临此问题的人来说,这是由于android:tint ImageView 属性引起的,我将图像设置为使用Glide。

当从URL加载实际图像时,我正在显示一个伪占位符图像,其中android:tint为灰色阴影。而这种色彩导致了问题。

因此,在使用 android:tint

加载图像后,请尝试一起删除imageView.setImageTintList(null)属性或以编程方式将色调设置为null。

希望有帮助