Android成长之路-实现简单动画
实现简单动画:
在drawable目录中放入图片,

并且创建xml文件 frame.xml 存入图片,如下:
- <pre class="html" name="code"><?xml version="1.0" encoding="utf-8"?>
- <animation-list xmlns:android="http://schemas.android.com/apk/res/android"
- android:oneshot="false">
- <!-- 可以重复添加,实现循环 -->
- <!-- android:duration="100"设置的是图片持续的时间长短 -->
- <item android:drawable="@drawable/girl_1" android:duration="100" />
- <item android:drawable="@drawable/girl_2" android:duration="100" />
- <item android:drawable="@drawable/girl_3" android:duration="100" />
- <item android:drawable="@drawable/girl_4" android:duration="100" />
- <item android:drawable="@drawable/girl_5" android:duration="100" />
- <item android:drawable="@drawable/girl_6" android:duration="200" />
- <item android:drawable="@drawable/girl_7" android:duration="300" />
- <item android:drawable="@drawable/girl_6" android:duration="200" />
- <item android:drawable="@drawable/girl_7" android:duration="300" />
- <item android:drawable="@drawable/girl_8" android:duration="200" />
- <item android:drawable="@drawable/girl_9" android:duration="100" />
- <item android:drawable="@drawable/girl_10" android:duration="100" />
- <item android:drawable="@drawable/girl_11" android:duration="100" />
- </animation-list>
- </pre><br>
- <pre></pre>
- <h3><a name="t3"></a>然后定义一个布局frame_layout.xml:</h3>
- <pre class="html" name="code"><?xml version="1.0" encoding="utf-8"?>
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:orientation="vertical"
- android:gravity="center" >
- <!-- 承载图片 -->
- <ImageView
- android:id="@+id/frameIV"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- />
- </LinearLayout></pre>
- <p><br>
- </p>
- <h3><a name="t4"></a>然后写activity类,FrameActivity.java:</h3>
- <pre class="java" name="code">package cn.class3g.animation;
- import android.app.Activity;
- import android.graphics.drawable.AnimationDrawable;
- import android.os.Bundle;
- import android.view.MotionEvent;
- import android.widget.ImageView;
- public class FrameActivity extends Activity {
- AnimationDrawable attackAnimation;//定义动画对象
- ImageView frameIV;
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- this.setContentView(R.layout.frame_layout);
- init();
- }
- private void init() {
- frameIV = (ImageView) this.findViewById(R.id.frameIV);
- frameIV.setBackgroundResource(R.drawable.frame);//得到图片并添加到布局中(当作背景图片)
- attackAnimation = (AnimationDrawable) frameIV.getBackground();//得到背景图片给动画对象
- }
- //点击屏幕触发
- public boolean onTouchEvent(MotionEvent event) {
- if(event.getAction() == MotionEvent.ACTION_DOWN){
- attackAnimation.start();//点击屏幕后启动动画
- }
- return super.onTouchEvent(event);
- }
- }
- </pre>
- <p><br>
- </p>
- <h3><a name="t5"></a>此时,在清单中注册后就可以运行并实现了</h3>
Android成长之路-实现简单动画的更多相关文章
- Android成长之路-编码实现软件界面
实现一个登陆界面: 相对布局: package cn.csdn.codeui; import android.app.Activity; import android.os.Bundle; impor ...
- Android成长之路-手势库的创建
手势库的创建: 使用SDK自带的例子GestureBuilder建立手势库,这个文件夹存在于android\android-sdk-windows \samples\android-10\Gest ...
- Android成长之路-手势识别的实现
手势识别系统: 先把手势库放到项目中:(创建手势库见下一篇博客) 在res文件夹下新建一个名为raw的文件夹,然后把手势库放进去 然后开始项目的创建: strings.xml: <?xml ...
- Android成长之路-LayoutInflater和inflate的用法
在这里用Tabhost的例子来说明: package cn.csdn.activity; import android.app.TabActivity; import android.os.Bundl ...
- Android成长之路-实现监听器的三种方法
第一种: 在Test类中 定义一个类接口OnClickListener 第二种:直接在Test类上写一个接口 其中的this相当于new OnClickListener()对象, 即class ...
- 【腾讯Bugly干货分享】JSPatch 成长之路
本文来自于腾讯bugly开发者社区,非经作者同意,请勿转载,原文地址:http://dev.qq.com/topic/579efa7083355a9a57a1ac5b Dev Club 是一个交流移动 ...
- Android学习之路——简易版微信为例(一)
这是“Android学习之路”系列文章的开篇,可能会让大家有些失望——这篇文章中我们不介绍简易版微信的实现(不过不是标题党哦,我会在后续博文中一步步实现这个应用程序的).这里主要是和广大园友们聊聊一个 ...
- redis成长之路——(一)
为什么使用redis Redis适合所有数据in-momory的场景,虽然Redis也提供持久化功能,但实际更多的是一个disk-backed的功能,跟传统意义上的持久化有比较大的差别,那么可能大家就 ...
- redis成长之路——(四)
加强redis连接的连接池 虽然StackExchange.Redis针对连接已经做了很多工作,不过在实际应用场景中还是不够的,比如多实例的vip就会导致只能连到其中一个实例上等:本实例中的连接池只能 ...
随机推荐
- Chrome无法播放m3u8格式的直播视频流的问题解决
出国,然后安装这个插件即可:Native HLS Playback https://chrome.google.com/webstore/detail/native-hls-playback/emnp ...
- java类中属性的加载顺序,以及内存分配情况介绍
看下面例子及说明: /** 假如有外部类调用了该类,代码为:new StaticTest(); 那么下面是类属性的加载顺序 */ public class StaticTest{ public int ...
- Tasker 中文版(4.6u2)
http://www.anzhi.com/soft_1868913.html Tasker绝对称得上是Android系统的神器之一,与Auto Memory Manager不同,Tasker不是加速型 ...
- Make a printer-port EEPROM programmer and dongle
You can easily use a PC's printer port for serial-EEPROM programming. You can use a device-programme ...
- promise和Rxjs的一点区别
promise 代码 let promise = new Promise( (resolve) => { setTimeout(() => { resolve('chen'); },200 ...
- 第一篇 对Javascript中原型的深入理解
理解原型对象 在Javascript中不管什么时候,仅仅要创建一个新的函数,就会依据一组特定的规则为该函数创建一个prototype属性,这个属性指向函数的原型对象(这个对象的用途是包括能够有特定 ...
- Multiline ComboBox
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- Python实现MapReduce,wordcount实例,MapReduce实现两表的Join
Python实现MapReduce 下面使用mapreduce模式实现了一个简单的统计日志中单词出现次数的程序: from functools import reduce from multiproc ...
- Mahout构建图书推荐系统【一起学Mahout】
阅读导读: 1.Mahout中推荐过滤算法支持哪两种算法? 2.用java代码怎样计算男性用户打分过的图书? 3.itemEuclidean.userEuclideanNoPref各自是什么算法? 1 ...
- 在线分享Oracle尖峰时刻--2014年中秋节尖峰在线福利!
********************************************************** 2014年中秋节尖峰在线福利!*************** ...