发布于 2016-02-20 00:27:31 | 137 次阅读 | 评论: 0 | 来源: 网友投递

这里有新鲜出炉的精品教程,程序狗速度看过来!

Android移动端操作系统

Android是一种基于Linux的自由及开放源代码的操作系统,主要使用于移动设备,如智能手机和平板电脑,由Google公司和开放手机联盟领导及开发。尚未有统一中文名称,中国大陆地区较多人使用“安卓”或“安致”。


这篇文章介绍了Android中AnimationDrawable使用的简单实例,有需要的朋友可以参考一下

首先,可以在drawable文件夹下定义一个xml的文件。如下所示:


<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
    android:oneshot="true">
    <item android:drawable="@drawable/compass_1" android:duration="70" />
    <item android:drawable="@drawable/compass_2" android:duration="70" />
    <item android:drawable="@drawable/compass_3" android:duration="70" />
    <item android:drawable="@drawable/compass_4" android:duration="70" />
    <item android:drawable="@drawable/compass_5" android:duration="70" />
</animation-list>

根标签为animation-list,其中oneshot代表着是否只展示一遍,设置为false会不停的循环播放动画。其中,每一个item是一帧,android:duration="400"表示每帧持续400ms,android:drawable是每帧要显示的图片。
接下来,代码中使用:


AnimationDrawable ad = (AnimationDrawable) getResources().getDrawable(R.drawable.bootanimation);

得到AnimationDrawable对象。再将该对象设为当前view的backgroud。


mView.setBackgroundDrawable(ad);

接着,就可以调用 ad.start()方法和ad.stop()方法来启动和停止该动画。
注意:必须设为当前view的background,否则start和stop该动画是没有效果的。



最新网友评论  共有(0)条评论 发布评论 返回顶部

Copyright © 2007-2017 PHPERZ.COM All Rights Reserved   冀ICP备14009818号  版权声明  广告服务