实现简单动画:

在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. BZOJ 1032 JSOI 2007 祖码Zuma 区间DP

    题目大意:依照祖玛的玩法(任意选颜色),给出一段区间.问最少用多少个球可以把全部颜色块都消除. 思路:把输入数据依照连续的块处理.保存成颜色和数量.然后用这个来DP.我们知道,一个单独的块须要两个同样 ...

  2. Android SDK最小需求

    As a minimum when setting up the Android SDK, you should download the latest tools and Android platf ...

  3. MP2359 1.2A, 24V, 1.4MHz Step-Down Converter in a TSOT23-6

    The MP2359 is a monolithic step-down switch mode converter with a built-in power MOSFET.It achieves ...

  4. hibernate将connection放进threadlocal里实现数据库连接池

    Why ThreadLocal? 无论如何,要编写一个多线程安全(Thread-safe)的程序是困难的,为了让线程共享资源,必须小心地对共享资源进行同步,同步带来一定的效能延迟,而另一方面,在处理同 ...

  5. [翻译] PBJNetworkObserver 网络监控

    PBJNetworkObserver 网络监控 https://github.com/piemonte/PBJNetworkObserver Introduction 'PBJNetworkObser ...

  6. [Android 新特性] Android 4.3新功能(正式发布前)

    腾讯数码讯(编译:徐萧梓丞)虽然谷歌公司目前尚未正式对外发布最新的Android 4.3果冻豆操作系统,但是在上周我们已经看到了关于三星正 在为原生版Galaxy S4进行Android 4.3系统进 ...

  7. Storm和Spark Streaming框架对比(转)

    原文链接:Storm和Spark Streaming框架对比 Storm和Spark Streaming两个都是分布式流处理的开源框架.但是这两者之间的区别还是很大的,正如你将要在下文看到的. 处理模 ...

  8. Hadoo生态中pHive HBase 项目的区别

    http://jenmhdn.iteye.com/blog/1678789 导读:Apache Hive是一个构建于Hadoop(分布式系统基础架构)顶层的数据仓库,Apache HBase是运行于H ...

  9. UTC 转本地时间

    String dateStr = "Wed Dec 10 00:00:00 UTC 0800 2014"; //Wed Dec 10 00:00:00 UTC 0800 2014 ...

  10. C#使用DirectShow播放视频文件 [转]

    原文网址:http://blog.csdn.net/openzpc/article/details/48442751 最近在开发一个视频播放软件,主要要求就是循环播放多个视频文件,并且要求两个视频文件 ...