Android 用Animation-list实现逐帧动画
2015-07-01 16:54
573 查看
我们要实现的效果
准备资源文件放到res/drawable
文件下中
light01.png
light02.png
light03.png
编写loading.xml
放到res/drawable
<!-- animation-list :根标签 oneshot :代表着是否只展示一遍,设置为false会不停的循环播放动画 android :duration 表示该图片的动画时长 --> <?xml version="1.0" encoding="utf-8"?> <animation-list xmlns:android="http://schemas.android.com/apk/res/android" android:oneshot="false" > <item android:drawable="@drawable/light01" android:duration="50"/> <item android:drawable="@drawable/light02" android:duration="50"/> <item android:drawable="@drawable/light03" android:duration="50"/> </animation-list>
在activity_main.xml
布局文件中,这样写
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical"> <ImageView android:id="@+id/main_img_loading" android:layout_width="wrap_content" android:layout_height="wrap_content" android:padding="5px" android:src="@drawable/loading"/> <Button android:id="@+id/main_bt_start" android:layout_width="wrap_content" android:layout_height="wrap_content" android:padding="5px" android:text="开始" /> <Button android:id="@+id/main_bt_stop" android:layout_width="wrap_content" android:layout_height="wrap_content" android:padding="5px" android:text="停止" /> </LinearLayout>
在Activity中这样来写
bt_start.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { //获取 AnimationDrawable animationDrawable = (AnimationDrawable) animationIV.getDrawable(); //开始动画 animationDrawable.start(); } }); bt_stop.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { //获取 AnimationDrawable animationDrawable = (AnimationDrawable) animationIV.getDrawable(); //停止动画 animationDrawable.stop(); } });
有兴趣的童鞋可以关注我的Blog,我的专栏会持续更新Android Studio 权威教程,以及2015 I/O大会上的NDK的配置和编译,我也全部会分享给大家。
并且我收到了CSND 的讲师邀请,后期我会把这些Android Studio的使用教程录制成视频。
/** * -------------- * 欢迎转载 | 转载请注明 * -------------- * 如果对你有帮助,请点击|顶| * -------------- * 请保持谦逊 | 你会走的更远 * -------------- * @author zsl * @github https://github.com/yy1300326388 * @blog http://blog.csdn.net/yy1300326388 */
相关文章推荐
- 获取SD卡下Android/data/下文件
- android style.xml的使用
- Android] Android XML解析学习——方式比较
- 【Android】【Framework】AndroidFramework之ContextImpl
- 【Android】【Framework】AndroidFramework之ContextImpl
- 【Android】【Framework】AndroidFramework之ContextImpl
- 【Android】【Framework】AndroidFramework之ContextImpl
- 【Android】【Framework】AndroidFramework之ContextImpl
- 【Android】【Framework】AndroidFramework之ContextImpl
- 【Android】【Framework】AndroidFramework之ContextImpl
- Android平台中实现对XML的三种解析方式
- Android listView 之万能Adapter
- android studio Process 'command
- Android使用NDK---函数参数传递-基本类型和数组
- android framework 框架层功能梳理
- Android开发者必须深入学习的10个应用开源项目
- Android_ListView详解
- Android程序完全退出的三种方法
- Android初体验之Monkey和MonkeyRunner
- Android初级教程_获取Android控件的宽和高