PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Sunday, July 17, 2022

[FIXED] How to display GIF file

 July 17, 2022     android, gif     No comments   

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)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

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

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing