0

I'm trying to show a GIF inside a loading dialog in my app, I'm using the glide image lib since of it's support for GIFS. When im trying to show the GIF in the dialog it doesnt present the GIF and only shows the dialog background. I have been searching around but i havent found a good solution.

My dialog code below

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()

}

1 Answers1

0

Someone can correct me if I am wrong, but out of the box ImageView does not support the Gif format.

You need to look at alternative formats, like hosting it in a WebView or using a library like this: https://github.com/koral--/android-gif-drawable

From 2013 ImageView not supporting Gifs: https://stackoverflow.com/a/16486771/413127

Android P way to do Gifs: https://medium.com/appnroll-publication/what-is-new-in-android-p-imagedecoder-animatedimagedrawable-a65744bec7c1


I will correct myself (yes its not supported, BUT):

Looks like Glide does some magic itself to make a Gif Drawable, see here: https://stackoverflow.com/a/34870817/413127

So for your example:

    GlideDrawableImageViewTarget imageViewTarget = new GlideDrawableImageViewTarget(imageView);
    imageView?.let { Glide.with(context).asGif().placeholder(R.drawable.redbull).into(imageViewTarget) }
Blundell
  • 75,855
  • 30
  • 208
  • 233
  • I tried your way with the GlidedrawableImageviewTarget it didnt work that well. I even tryed out Glide on a fresh project and it worked with this line of code Glide.with(applicationContext).asGif().load(R.drawable.redbull).into(imageView), which is very strange in my mind –  Oct 31 '19 at 10:11
  • try loading a normal image into your Dialog using Glide, to see if the problem is with a gif. Also try loading a static image to see if the problem is with Glide. – Blundell Oct 31 '19 at 12:00
  • I did what you said still no image is showing up, i can get a image showing when i put android:src in the xml layout but that is not necessary here –  Oct 31 '19 at 13:26
  • ok is `R.id.glideImage` inside of `R.layout.progress_layout`? i.e. instead of finding the imageView inside `init` find it in `showDialog` with `dialogView.findViewById(R.id.glideImage)` – Blundell Oct 31 '19 at 13:31
  • Yes i tryed this aswell and it didnt work. im Abit lost now how to solve this its very strange –  Oct 31 '19 at 13:52
  • hey man its fixed now i did a refresh gradle build and it works now. superduper thanks for your help and time Blundell much thanks again! –  Oct 31 '19 at 13:56