实现简单动画:

在drawable目录中放入图片,

并且创建xml文件 frame.xml 存入图片,如下:

    1. <pre class="html" name="code"><?xml version="1.0" encoding="utf-8"?>
    2. <animation-list xmlns:android="http://schemas.android.com/apk/res/android"
    3. android:oneshot="false">
    4. <!-- 可以重复添加,实现循环 -->
    5. <!-- android:duration="100"设置的是图片持续的时间长短 -->
    6. <item android:drawable="@drawable/girl_1" android:duration="100" />
    7. <item android:drawable="@drawable/girl_2" android:duration="100" />
    8. <item android:drawable="@drawable/girl_3" android:duration="100" />
    9. <item android:drawable="@drawable/girl_4" android:duration="100" />
    10. <item android:drawable="@drawable/girl_5" android:duration="100" />
    11. <item android:drawable="@drawable/girl_6" android:duration="200" />
    12. <item android:drawable="@drawable/girl_7" android:duration="300" />
    13. <item android:drawable="@drawable/girl_6" android:duration="200" />
    14. <item android:drawable="@drawable/girl_7" android:duration="300" />
    15. <item android:drawable="@drawable/girl_8" android:duration="200" />
    16. <item android:drawable="@drawable/girl_9" android:duration="100" />
    17. <item android:drawable="@drawable/girl_10" android:duration="100" />
    18. <item android:drawable="@drawable/girl_11" android:duration="100" />
    19. </animation-list>
    20. </pre><br>
    21. <pre></pre>
    22. <h3><a name="t3"></a>然后定义一个布局frame_layout.xml:</h3>
    23. <pre class="html" name="code"><?xml version="1.0" encoding="utf-8"?>
    24. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    25. android:layout_width="match_parent"
    26. android:layout_height="match_parent"
    27. android:orientation="vertical"
    28. android:gravity="center" >
    29. <!-- 承载图片 -->
    30. <ImageView
    31. android:id="@+id/frameIV"
    32. android:layout_width="wrap_content"
    33. android:layout_height="wrap_content"
    34. />
    35. </LinearLayout></pre>
    36. <p><br>
    37. </p>
    38. <h3><a name="t4"></a>然后写activity类,FrameActivity.java:</h3>
    39. <pre class="java" name="code">package cn.class3g.animation;
    40. import android.app.Activity;
    41. import android.graphics.drawable.AnimationDrawable;
    42. import android.os.Bundle;
    43. import android.view.MotionEvent;
    44. import android.widget.ImageView;
    45. public class FrameActivity extends Activity {
    46. AnimationDrawable attackAnimation;//定义动画对象
    47. ImageView frameIV;
    48. protected void onCreate(Bundle savedInstanceState) {
    49. super.onCreate(savedInstanceState);
    50. this.setContentView(R.layout.frame_layout);
    51. init();
    52. }
    53. private void init() {
    54. frameIV = (ImageView) this.findViewById(R.id.frameIV);
    55. frameIV.setBackgroundResource(R.drawable.frame);//得到图片并添加到布局中(当作背景图片)
    56. attackAnimation = (AnimationDrawable) frameIV.getBackground();//得到背景图片给动画对象
    57. }
    58. //点击屏幕触发
    59. public boolean onTouchEvent(MotionEvent event) {
    60. if(event.getAction() == MotionEvent.ACTION_DOWN){
    61. attackAnimation.start();//点击屏幕后启动动画
    62. }
    63. return super.onTouchEvent(event);
    64. }
    65. }
    66. </pre>
    67. <p><br>
    68. </p>
    69. <h3><a name="t5"></a>此时,在清单中注册后就可以运行并实现了</h3>

Android成长之路-实现简单动画的更多相关文章

  1. Android成长之路-编码实现软件界面

    实现一个登陆界面: 相对布局: package cn.csdn.codeui; import android.app.Activity; import android.os.Bundle; impor ...

  2. Android成长之路-手势库的创建

      手势库的创建: 使用SDK自带的例子GestureBuilder建立手势库,这个文件夹存在于android\android-sdk-windows \samples\android-10\Gest ...

  3. Android成长之路-手势识别的实现

      手势识别系统: 先把手势库放到项目中:(创建手势库见下一篇博客) 在res文件夹下新建一个名为raw的文件夹,然后把手势库放进去 然后开始项目的创建: strings.xml: <?xml  ...

  4. Android成长之路-LayoutInflater和inflate的用法

    在这里用Tabhost的例子来说明: package cn.csdn.activity; import android.app.TabActivity; import android.os.Bundl ...

  5. Android成长之路-实现监听器的三种方法

      第一种:  在Test类中  定义一个类接口OnClickListener 第二种:直接在Test类上写一个接口 其中的this相当于new OnClickListener()对象, 即class ...

  6. 【腾讯Bugly干货分享】JSPatch 成长之路

    本文来自于腾讯bugly开发者社区,非经作者同意,请勿转载,原文地址:http://dev.qq.com/topic/579efa7083355a9a57a1ac5b Dev Club 是一个交流移动 ...

  7. Android学习之路——简易版微信为例(一)

    这是“Android学习之路”系列文章的开篇,可能会让大家有些失望——这篇文章中我们不介绍简易版微信的实现(不过不是标题党哦,我会在后续博文中一步步实现这个应用程序的).这里主要是和广大园友们聊聊一个 ...

  8. redis成长之路——(一)

    为什么使用redis Redis适合所有数据in-momory的场景,虽然Redis也提供持久化功能,但实际更多的是一个disk-backed的功能,跟传统意义上的持久化有比较大的差别,那么可能大家就 ...

  9. redis成长之路——(四)

    加强redis连接的连接池 虽然StackExchange.Redis针对连接已经做了很多工作,不过在实际应用场景中还是不够的,比如多实例的vip就会导致只能连到其中一个实例上等:本实例中的连接池只能 ...

随机推荐

  1. StoryBoard学习(5):使用segue页面间传递数据

    StoryBoard学习(5):使用segue页面间传递数据 函数: - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sen ...

  2. iOS开发读取plist文件、iphone中plist文件的

    在Xcode中建立一个iOS项目后,会自己产生一个.plist文件,点击时会看见它显示的是类似于excel表格: 但是,如果打开方式选择Source Code,你会看见它其实是一个xml文件. 我们会 ...

  3. Java性能优化的9大工具

    在这篇文章中,我会带着大家一起看一下9个可以帮助我们优化Java性能的工具.有一些我们已经在IDR Solutions中使用了,而另外一些有可能在个人项目中使用. NetBeans Profiler ...

  4. HF Reader

  5. sourceinsight使用技巧

    转:http://blog.csdn.net/flyyanqu/article/details/2222799 目录(?)[-] 配置成简单好用的cjava代码编辑器 缩进与tab 向项目中添加文件时 ...

  6. SharePoint 2013 App 示例之图片墙

    应用程序实质上是 Web 应用程序.如果您知道如何生成 Web 应用程序,则您就知道如何生成 SharePoint 相关应用程序.您可以使用任何语言,如 HTML.JavaScript.PHP 或 . ...

  7. 解决用户自生成meta导入kylin后报错问题Can not deserialize instance of java.lang.String[] out of VALUE_STRING token

    报错栈: -- ::, ERROR [http-bio--exec-] cube.CubeManager: : Error during load cube instance, skipping : ...

  8. IE8 通过Jquery动态修改html不显示的问题

    for (var i = 0; i < _priority_transf.length && i < xmlList.length; i++) { if (textCont ...

  9. 讨论一下TaskManager中监控磁盘性能的一些小问题

    今天研究了一下命令"diskperf -Y". 我把发现Share给了同事, 原文写在了下面, 就不翻译了. ^_^   Try this command (CMD or Powe ...

  10. 数据库 DB MySQL 基本操作 CRUD 多表 MD

    操作数据库 创建数据库:create 创建一个名称为mydb1的数据库 create database mydb1; 创建一个使用gbk字符集的mydb2数据库 create database myd ...