手机
当前位置:查字典教程网 >编程开发 >安卓软件开发 >Android中播放Gif动画取巧的办法
Android中播放Gif动画取巧的办法
摘要:由于做的项目,要有个动画的等待效果,第一时间想到的就是Gif(懒,省事),但是试了好多据说能播放Gif的控件,也写过,但是放到魅族手机上就是...

由于做的项目,要有个动画的等待效果,第一时间想到的就是Gif(懒,省事),但是试了好多据说能播放Gif的控件,也写过,但是放到魅族手机上就是不能播放,所有就想了个招,既然Gif能在浏览器上播放,那android 的 WebView 也能播放,写了个Demo,果然能播放。

1、将gif的文件放到android的资源文件夹里面

2、写个html,将android的gif源放到WebView里面去加载

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity"> <WebView android:id="@+id/webview" android:layout_width="match_parent" android:layout_height="match_parent"> </WebView> </RelativeLayout>

3、代码中使用

@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); WebView webView = (WebView) findViewById(R.id.webview); webView.loadDataWithBaseURL(null, "<HTML><body bgcolor='#f3f3f3'><div align=center><IMG src='file:///android_asset/load_wait_1_gif.gif'/></div></body></html>", "text/html", "UTF-8",null); }

好了,现在就可以播放了,感觉能够适配任何机型。

以上所述是小编给大家介绍的Android中播放Gif动画取巧的办法,希望对大家有所帮助!

【Android中播放Gif动画取巧的办法】相关文章:

Android实现图片循环播放的实例方法

在Android中访问WebService接口的方法

Android 九宫格的实现方法

Android中将一个图片切割成多个图片的实现方法

Android Handler之消息循环的深入解析

Android读取对应的键值

Android界面刷新的方法分享

Android4.2中全屏或者取消标题栏的方法总结

Android自动禁用布局里的所有子控件

Android 开发中需要注意到的小细节

精品推荐
分类导航