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 ...
随机推荐
- ubuntu16.04 linux 编译安装apache2.4.33
下载软件包: wget http://mirror.bit.edu.cn/apache//httpd/httpd-2.4.33.tar.gz wget http://mirrors.tuna.tsin ...
- Codeforces731C(SummerTrainingDay06-M 并查集)
C. Socks time limit per test:2 seconds memory limit per test:256 megabytes input:standard input outp ...
- HDU1257(dp)
最少拦截系统 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Subm ...
- 排序算法(4)--Selection Sorting--选择排序[1]--Simple Selection Sort--简单(直接)选择排序
1.基本思想 在要排序的一组数中,选出最小的一个数与第一个位置的数交换:然后在剩下的数当中再找最小的与第二个位置的数交换,如此循环到倒数第二个数和最后一个数比较为止. 2.实现原理 每趟从待排序的 ...
- 解决The type 'ASP.global_asax' exists in both ASP.global_asax同时存在问题
习惯发布站点的同学有时候可能遇见以下错误 这是发布时[预编译勾选/不勾选]产生的文件冲突导致的 如果不勾选预编译会发布以下代码 如果勾选预编译会发布以下代码 错误就在于此,如果非预编译Global.a ...
- atitit.交换机 汇聚上联、网络克隆和标准共享的原理与区别
atitit.交换机 汇聚上联.网络克隆和标准共享的原理与区别 1. 标准共享(标准化模式)1 2. 汇聚上联trunk1 2.1. 使用场合1 2.2. 背景1 2.3. 实现原理2 3. 网络克隆 ...
- Android Design Support Library(二)用NavigationView实现抽屉菜单界面
NavigationView在MD设计中非常重要,之前Google也提出了使用DrawerLayout来实现导航抽屉.这次,在Android Design Support Library中,Googl ...
- Android--用Valley框架去上传图片
1.除了用到了Volley,还用到了一个包httpmime(下载地址:http://download.csdn.net/detail/chequer_lkp/8102751) 2.需要一个工具类,该类 ...
- springboot 学习之路 17(webflux 入门 (1))
Webflux: webflux是在springboot2系列引入的技术:补充一些概念: 1> Reactive Streams 是 JVM 中面向流的库标准和规范: 处理可能无限数量的元素 按 ...
- LeetCode题解之 Increasing Order Search Tree
1.题目描述 2/问题分析 利用中序遍历,然后重新构造树. 3.代码 TreeNode* increasingBST(TreeNode* root) { if (root == NULL) retur ...