Android中播放Gif动画取巧的办法
Android中播放Gif动画取巧的办法
发布时间:2016-12-28 来源:查字典编辑
摘要:由于做的项目,要有个动画的等待效果,第一时间想到的就是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动画取巧的办法,希望对大家有所帮助!

推荐文章
猜你喜欢
附近的人在看
推荐阅读
拓展阅读
相关阅读
网友关注
最新安卓软件开发学习
热门安卓软件开发学习
编程开发子分类