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?
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.
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.
Android devices have not had built-in animated GIF support, which causes GIFs to load slower on some Android phones than on other OS.
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>
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/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With