我们要实现的效果

准备资源文件放到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 */

更多相关文章

  1. 一款常用的 Squid 日志分析工具
  2. GitHub 标星 8K+!一款开源替代 ls 的工具你值得拥有!
  3. RHEL 6 下 DHCP+TFTP+FTP+PXE+Kickstart 实现无人值守安装
  4. Linux 环境下实战 Rsync 备份工具及配置 rsync+inotify 实时同步
  5. Android界面设计的一点体会
  6. Android(安卓)反编译apk
  7. Android中实现ListView横向滑动
  8. android wifi连接+基于socket的文件数据传输(上)
  9. android命令备忘

随机推荐

  1. 【错误】:MySql Host is blocked because
  2. MariaDB 和 MySQL 全面对比:选择数据库需
  3. mysql管理之安全机制
  4. 在社交新闻网站上处理上/下投票
  5. MySQL高可用性之Keepalived+Mysql
  6. mysql 服务意外停止1067错误解决办法小结
  7. 如何在PhpMyAdmin中列出/查看存储过程
  8. ASP.NET GridView 绑定 MySql数据库
  9. MYSQL学习笔记2之MySQL 管理
  10. vmware12下的centos7 linux 安装 mysql5.