我已经尝试了几种不同的方法,但是imageview仍然只显示一个灰色方块。我正在API 17上进行测试。
以下是我尝试失败的选项:
将XML中的ImageView配置为:
固定的宽度和高度; wrap_content的宽度和高度;宽度到match_parent,高度到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);
当前xml:
<ImageView
android:layout_width="150dp"
android:layout_height="150dp"
android:layout_centerHorizontal="true"
android:id="@+id/captcha"/>
对于仍然面临此问题的人,对我来说,这是由于我使用Glide将图像设置为的android:tint
的[[ImageView
属性所致。
android:tint
显示为灰色阴影的虚拟占位符图像。那是造成问题的原因。因此,请尝试一起删除android:tint
属性,或在使用imageView.setImageTintList(null)
加载图像后将其设置为null
希望有帮助