如何在对话框中显示GIF与滑动库的帮助



我正试图在我的应用程序中的加载对话框中显示GIF,由于它支持GIF,我正在使用glide image lib。当我试图在对话框中显示GIF时,它不会显示GIF,只显示对话框背景。我一直在四处寻找,但没有找到一个好的解决办法。

下方的对话框代码

class ShowProgress(context: Context) : Dialog(context) {
var dialog: Dialog? = null
var imageView: ImageView? = null
init {
dialog = Dialog(context)
imageView = findViewById(R.id.glideImage)
}
fun showDialog(context: Context) {
val dialogView = LayoutInflater.from(context).inflate(R.layout.progress_layout, null, false)
imageView?.let { Glide.with(context).asGif().placeholder(R.drawable.redbull).into(it) }
dialog?.setCancelable(false)
dialog?.setContentView(dialogView)
dialog?.show()
}

如果我错了,有人可以纠正我,但开箱即用的ImageView不支持Gif格式。

您需要考虑其他格式,例如将其托管在WebView中或使用这样的库:https://github.com/koral--/android-gif-drawable

从2013年起,ImageView不支持Gifs:https://stackoverflow.com/a/16486771/413127

安卓p做Gifs的方式:https://medium.com/appnroll-publication/what-is-new-in-android-p-imagedecoder-animatedimagedrawable-a65744bec7c1


我会自我纠正(是的,不支持,但(:

看起来Glide本身也有一些魔力,可以让Gif Drawable,请参阅此处:https://stackoverflow.com/a/34870817/413127

举个例子:

GlideDrawableImageViewTarget imageViewTarget = new GlideDrawableImageViewTarget(imageView);
imageView?.let { Glide.with(context).asGif().placeholder(R.drawable.redbull).into(imageViewTarget) }

最新更新