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就会导致只能连到其中一个实例上等:本实例中的连接池只能 ...
随机推荐
- 从网络得到数据--Arduino+以太网
昨天我们讨论了如何使用Arduino以太网插板建立服务器,并通过网络控制Arduino的引脚.今天我们来看看用插板做为客户端来从一个网页上得到信息并返回报告.我几个月前用的这个方法,当时我做了一个Ni ...
- Use an LM317 as 0 to 3V adjustable regulator
Most engineers know that they can use an inexpensive, three-terminal adjustable regulator, such as F ...
- MemoryModule -- load a DLL completely from memory
https://github.com/fancycode/MemoryModule MemoryModule is a library that can be used to load a DLL c ...
- win8升级8.1提示卸载sentinel runtime drivers
Win8升级8.1时提示需卸载sentinel runtime drivers的解决方法 第一步:打开sentinelcustomer.safenet-inc.com/sentineldownload ...
- 全面的framebuffer详解一
转:http://blog.chinaunix.net/uid-20628575-id-72534.html 一.FrameBuffer的原理 FrameBuffer 是出现在 2.2.xx 内核当中 ...
- Debian 安装记录
1.蓝色标注是安装的部分或配置的. 作者:http://www.cppblog.com/jinglexy上海体育馆 2.linux 发行版测评网站:www.distrowatch.com 打 ...
- VB--"." 和 "!" ?
在做学生信息管理系统的时候,遇到了一条代码. txtName.Text = mrc!student_Name txtResult.Text = mrc!result 代码本身理解没有问题,给文本框添加 ...
- Win7+Qt5.6.0(64位)+msvc2015编译器 环境配置
根据“Qt简介,Qt 5.6.0-VS2015 版本安装配置图文教程”安装第二套IDE,使用Qt官方的集成开发环境 QtCreator + 微软的WinDbg调试器(内含命令行调试器为CDB)的组合. ...
- django 实现上传文件功能
需求:自己写一个文件上传功能 代码: urls.py from django.conf.urls import url from django.contrib import admin from ap ...
- Minify压缩JS和CSS
Minify把CSS和JS压缩和削减(Minify:去掉空格回车符等),以及把多个CSS,JS文件整合到一个文件里.不要以为你的大带宽没有必要进行这类优化.使用它的理由更重要的是文件合并,而不是压缩, ...