Android Frame动画demo
Android动画介绍:Android为我们提供了两种动画实现,Frame和Tween。
两者之间的区别:
1.Frame动画:就像放电影一样,是通过预先做好的图片进行连续播放从而形成动画效果
2.Tween动画:通过对图片设置平移、缩放、旋转、改变透明度等方式来显示动画效果
本节仅讲Frame动画,
Frame动画是通过AnimationDrawable来实现的,它提供了start()和stop()两个方法,对播放的动画进行控制,一般通过XML文件配置,在工程的res/anim目录下创建一个XML配置文件,该配置文件有一个<animation-list>根元素和若干个<item>子元素。
废话就不说了,下面将贴出该例子的完整代码,供大家测试使用:
一、FrameActivity
package com.yw.myapiupdate.frame; import com.yw.myapiupdate.R; import android.app.Activity;
import android.graphics.drawable.AnimationDrawable;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView; /**
*
* 实现动画轮询播放
* @author yw-tony
*
*/
public class FrameActivity extends Activity implements OnClickListener{
private Button btn_start;
private Button btn_end;
private ImageView iv;
private AnimationDrawable ad;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.frame_layout);
initViews();
}
private void initViews(){
btn_start = (Button)findViewById(R.id.frame_btn_start);
btn_end = (Button)findViewById(R.id.frame_btn_end);
iv = (ImageView)findViewById(R.id.frame_iv);
btn_start.setOnClickListener(this);
btn_end.setOnClickListener(this);
this.ad = (AnimationDrawable)iv.getBackground();
}
private void startAnimation(){
this.ad.start();
}
private void stopAnimation(){
this.ad.stop();
}
@Override
public void onClick(View v) {
switch(v.getId()){
case R.id.frame_btn_start:
startAnimation();
break;
case R.id.frame_btn_end:
stopAnimation();
break;
}
}
}
与之对应的xml文件
<?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:gravity="center"
android:orientation="vertical" >
<ImageView
android:id="@+id/frame_iv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@anim/framedrawable"/>
<Button
android:id="@+id/frame_btn_start"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="start"/>
<Button
android:id="@+id/frame_btn_end"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="end"/>
</LinearLayout>
二、设置动画的xml文件
<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:apk="http://schemas.android.com/apk/res/android" apk:oneshot="false">
<item apk:drawable="@drawable/anim_1" apk:duration="200" />
<item apk:drawable="@drawable/anim_2" apk:duration="200" />
<item apk:drawable="@drawable/anim_3" apk:duration="200" />
<item apk:drawable="@drawable/anim_4" apk:duration="200" />
<item apk:drawable="@drawable/anim_5" apk:duration="200" />
<item apk:drawable="@drawable/anim_6" apk:duration="200" />
</animation-list>
下面是源代码以及资源文件的下载地址:
http://files.cnblogs.com/tony-yang-flutter/anni.zip
Android Frame动画demo的更多相关文章
- Android Animation 动画Demo(Frame帧动画)
上一页介绍Animation动画第一:Tween吐温动画. 本文介绍了以下Animation也有动画的形式:Frame帧动画. Frame动画是一系列照片示出的顺序按照一定的处理,和机制,以放电影很阶 ...
- android之frame动画详解
上一篇我们说了android中的tween动画,这一篇我们说说frame动画,frame动画主要是实现了一种类似于gif动画的效果,就是多张图按预先设定好的时间依次连续显示. 新建一个android项 ...
- 我的Android进阶之旅------>Android之动画之Frame Animation实例
============================首先看看官网上关于Frame animation的介绍================================ 地址:http://de ...
- Android 动画具体解释Frame动画 (Drawable Animation)
Frame动画像gif画画,通过一些静态的图片,以实现动画效果. Android sdk该AnimationDrawable就是专门针对Frame动画,当然Frame动画也可在java代码或者xml中 ...
- android 自定义动画
android自定义动画注意是继承Animation,重写里面的initialize和applyTransformation,在initialize方法做一些初始化的工作,在applyTransfor ...
- Frame动画实战
Android动画分为Tween动画和Frame动画,Tween动画主要包括图片的放大缩小.旋转.透明度变化.移动等等操作:Frame动画则简单得多了,就是把一张张的图片连续播放产生动画效果. 本节主 ...
- 79.Android之动画基础
转载:http://a.codekk.com/detail/Android/lightSky/%E5%85%AC%E5%85%B1%E6%8A%80%E6%9C%AF%E7%82%B9%E4%B9%8 ...
- Android的动画
一.动画类型 Android的animation由四种类型组成:alpha.scale.translate.rotate XML配置文件中 alpha 渐变透明度动画效果 scale 渐变尺寸伸缩动画 ...
- Android View动画
Animation TypeEvaluator View的animate方法 ValueAnimator ObjectAnimator AnimatorSet 使用xml来创建动画 animation ...
随机推荐
- 小程序 波浪进度球 wave
直接上代码: //index.js //获取应用实例 const app = getApp() var wave = function (ctx, oRange){ var tid; //oRange ...
- DVWA的安装
DVWA(Dam Vulnerable Web Application)是基于PHP+Mysql的一套用于常规Web漏洞教学和检测Web脆弱性测试程序,包含了SQL注入,Xss,盲注等常用的一些安全漏 ...
- 【java】一些零碎的知识点
java注释文档 一些常用的javadoc标签 常用javadoc标签 @see: other-class 引用other-class 生成的html文档会有一个See Alse 作为超链接的只是条目 ...
- ArcGIS三种方式打断相交线------Feature To Line工具
有多个layer图层相交线时,选用”Feature To Line“工具,将多个图层相交线打断,然后合并成一个图层. (1) 选择工具栏”Geoprocessing“中的”ArcToolb ...
- Oracle 修改SYS、system用户密码
Oracle 修改SYS.system用户密码 by:授客 QQ:1033553122 概念 SYS用户是Oracle中权限最高的用户,而SYSTEM是一个用于数据库管理的用户.在数据库安装完之后,应 ...
- flutter 调用原生(获取当前设备电池电量)
代码: import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'dart:asy ...
- View的layout机制
View框架的工作流程为:测量每个View大小(measure)-->把每个View放置到相应的位置(layout)-->绘制每个View(draw). 源代码分析 在View的源代码中, ...
- 《图解HTTP》
第一章.了解web及网络基础 1.2 http的诞生 HTTP于1990年问世,那时候HTTP并没有作为正式的标准被建立,被称为HTTP/0.9 HTTP正式作为标准被公布是在1996年5月,版本被命 ...
- Leetcode题解之Valid Palindrome II
1.题目描述 2.问题分析 使用两个下标,检测下标对应的字符是否相等,若不相等,则考察子串. 3.代码 bool validPalindrome(string s) { , j = s.size()- ...
- Oracle EBS OM 已存在的OM订单增加物料
DECLARE l_header_rec OE_ORDER_PUB.Header_Rec_Type; l_line_tbl OE_ORDER_PUB.Line_Tbl_Type; l_action_r ...