Cannot properly display large Gifs using Glide in Android?

28 views Asked by At

I have the following code

val params = RelativeLayout.LayoutParams(WRAP_CONTENT, WRAP_CONTENT)

params.leftMargin = 0
params.topMargin = 0

val contentLayout: View = inflater.inflate(R.layout.content_layout, null, false)
val imageView = contentLayout.findViewById<ImageView>(R.id.sub_image)
val imageViewTarget = DrawableImageViewTarget(imageView)
Glide.with(context).load(imageUri).into(imageViewTarget)

...
// parentView: ViewGroup
parentView.addView(contentButtonLayout, params)

In the above code, I'm adding contentLayout View to parentGroup at top left corner. The contentLayout contains imageView which is set to a gif file.

The problem is, I have a gif file that's 120MB and it's dimensions are 1920 × 490 (1920 is the full width of the screen). When that is loaded on the device, imageView's height should = Gif's height. However, ImageView takes up entire screen (verified through layout inspector) and the gif animation is in the middle of the screen (the animation doesn't even play).

Under layout inspector, I see

measuredHeight = -5032624dp
measuredHeightAndState  -5032624dp

I compressed the gif file to 20 MB and the gif loads correctly. ImageView doesn't take up entire screen's height and the animation plays. Also

measuredHeight = 245dp
measuredHeightAndState  245dp

So I'm wondering if there's something wrong with my uncompressed gif file or if Glide/ImageView cannot handle large Gif files

0

There are 0 answers