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就会导致只能连到其中一个实例上等:本实例中的连接池只能 ...
随机推荐
- StoryBoard学习(5):使用segue页面间传递数据
StoryBoard学习(5):使用segue页面间传递数据 函数: - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sen ...
- iOS开发读取plist文件、iphone中plist文件的
在Xcode中建立一个iOS项目后,会自己产生一个.plist文件,点击时会看见它显示的是类似于excel表格: 但是,如果打开方式选择Source Code,你会看见它其实是一个xml文件. 我们会 ...
- Java性能优化的9大工具
在这篇文章中,我会带着大家一起看一下9个可以帮助我们优化Java性能的工具.有一些我们已经在IDR Solutions中使用了,而另外一些有可能在个人项目中使用. NetBeans Profiler ...
- HF Reader
- sourceinsight使用技巧
转:http://blog.csdn.net/flyyanqu/article/details/2222799 目录(?)[-] 配置成简单好用的cjava代码编辑器 缩进与tab 向项目中添加文件时 ...
- SharePoint 2013 App 示例之图片墙
应用程序实质上是 Web 应用程序.如果您知道如何生成 Web 应用程序,则您就知道如何生成 SharePoint 相关应用程序.您可以使用任何语言,如 HTML.JavaScript.PHP 或 . ...
- 解决用户自生成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 : ...
- IE8 通过Jquery动态修改html不显示的问题
for (var i = 0; i < _priority_transf.length && i < xmlList.length; i++) { if (textCont ...
- 讨论一下TaskManager中监控磁盘性能的一些小问题
今天研究了一下命令"diskperf -Y". 我把发现Share给了同事, 原文写在了下面, 就不翻译了. ^_^ Try this command (CMD or Powe ...
- 数据库 DB MySQL 基本操作 CRUD 多表 MD
操作数据库 创建数据库:create 创建一个名称为mydb1的数据库 create database mydb1; 创建一个使用gbk字符集的mydb2数据库 create database myd ...