Sunday, July 17, 2022

[FIXED] How to display GIF file

Issue

I'm using this library as a guide to display a 'gif' file. When using the saved gif in drawableit display correctly the gif I call it like this

<pl.droidsonroids.gif.GifImageView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/imgView1"
    android:src="@drawable/gifFile"
    />

but when removing the src and tried like initializing the GifImageView in the Activity like this

 GifImageView gifFromFile = (GifImageView) findViewById(R.id.imgView1);
gifFromFile.setImageBitmap(Utils.getBitmapImagefromStorage(context, imageHome));

Where getBitmapImagefromStorage get the path and imageHome gets the filename the gif file doesn't play its only display like an image. It was said that If given drawable is not a GIF then mentioned Views work like plain ImageView and ImageButton. But the file I'm providing is a gif.I'm wondering if I'm using it correctly.

Also the file can be png or gif so I needed to support the two.


Solution

I tried using GifDrawable

File gifFile = new File(context.getExternalFilesDir(null)
                    .getAbsolutePath(), imageHome);
GifDrawable gifFromPath  = new GifDrawable(gifFile);

And then instead of using setImageBitmap I use setImageDrawable

GifImageView gifImageView = (GifImageView) findViewById(R.id.textViewDealFinder);
        gifImageView.setImageDrawable(gifFromPath);


Answered By - natsumiyu
Answer Checked By - Mildred Charles (PHPFixing Admin)

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.