如何通过glide lib在对话框中显示GIF

问题描述 投票:-1回答:1

im试图在我的应用程序的加载对话框中显示GIF,由于它支持GIFS,因此我使用了滑动图像库。当我试图在对话框中显示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()

}
android android-layout kotlin android-glide android-dialog
1个回答
0
投票

如果我错了,有人可以纠正我,但是现成的ImageView不支持Gif格式。

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

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

Android P做Gif的方式:https://medium.com/appnroll-publication/what-is-new-in-android-p-imagedecoder-animatedimagedrawable-a65744bec7c1

看起来Glide本身做了一些魔术来制作Gif Drawable,请参见此处:https://stackoverflow.com/a/34870817/413127

© www.soinside.com 2019 - 2024. All rights reserved.