Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to play a GIF file in Android?

I want to play a GIF file in my current activity.

I have an XML file in which there is a layout.

I want to play the GIF in the same class Activity.

Is there a simple way to play a GIF file in an Activity class?

like image 563
Siten Avatar asked Sep 05 '11 10:09

Siten


People also ask

How can I play GIFs on my Android?

Android smartphones have a built-in image viewing application called Gallery. When you connect your Android smartphone to your computer and transfer a GIF file to your phone's storage area, you can open the Gallery appliation and view that GIF file.

How do I play a GIF file?

GIFs have wide compatibility — they can be opened through most major image and video editing programs. GIFs are also easy to open through web-based browsers, including Chrome, Firefox, and Internet Explorer. In the case of Internet Explorer, simply click on the File menu and then Open.

Why do GIFs not work on my Android?

Android devices have not had built-in animated GIF support, which causes GIFs to load slower on some Android phones than on other OS.


2 Answers

You can use a webView. I will show with an example:

//My activity
public class Gift_Loading extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        Gif_loading_View view = new Gif_loading_View(this); 
        setContentView(view);
    }

}

//the webView
public class Gif_loading_View extends WebView{

    public Gif_loading_View(Context context) {

        super(context);     
        loadUrl("file:///android_asset/loading_position.html");

        } 
}

In the assets folder add this html file:

<html>
<body bgcolor="white">
    <table width="100%" height="100%">
        <tr>
            <td align="center" valign="center">                
                <br/>
                <br/>
                <br/>
                <font size="6">Please wait...</font>
                <br/>
                <br/>
                <img src="cyclist_loading.gif" />

            </td>
        </tr>
    </table>
</body>
like image 153
Blitz Avatar answered Oct 21 '22 07:10

Blitz


Android doesn't support the playing of animated GIF files. If you need to play them then you need to break them apart into frames, and animate each frame one by one.

This will let you split up the GIF file http://www.xoyosoft.com/gs/

like image 2
Ollie C Avatar answered Oct 21 '22 09:10

Ollie C