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 ...
随机推荐
- 自定义MVC框架之工具类-图像处理类
截止目前已经改造了4个类: ubuntu:通过封装验证码类库一步步安装php的gd扩展 自定义MVC框架之工具类-分页类的封装 自定义MVC框架之工具类-文件上传类 图像处理类: 1,图片加水印处理( ...
- JS简单验证
1.验证是否全为数字 2.验证邮箱 3验证手机号 4.验证身份证号 5.验证时间格式 下面是代码,可直接用,有注释 <html> <meta charset="utf-8& ...
- 排序算法(2)--Insert Sorting--插入排序[2]--binary insertion sort--折半(二分)插入排序
作者QQ:1095737364 QQ群:123300273 欢迎加入! 1.基本思想 二分法插入排序的思想和直接插入一样,只是找合适的插入位置的方式不同,这里是按二分法找到合适的位置,可 ...
- Oracle 12c SQL Developer连接报错(ORA-12505)
Oracle 12c SQL Developer连接报错(ORA-12505) 连接时报错码:Listener refused the connection with following error: ...
- VMware Linux下拖拽补丁vmtools的安装和卸载
Linux下拖拽补丁vmtools的安装和卸载 by:授客 QQ:1033553122 Vmware 8.0.4为例子 步骤1.VM->Install Vmware Tools... 步骤2.查 ...
- 2018-10-19 00:13:35 ArrayList
获取集合元素的长度用的是size方法. 传入Object类型的值,返回boolean值的remove方法,含义是判断是否删除成功. 传入索引值的remove方法,返回的是被删除的元素. 修改值得set ...
- 并发容器(四)ConcurrentHashMap 深入解析(JDK1.6)
这篇文章深入分析的是 JDK1.6的 ConcurrentHashMap 的实现原理,但在JDK1.8中又改进了 ConcurrentHashMap 的实现,废弃了 segments.虽然是已经被 ...
- CSS 小结笔记之图标字体(IconFont)
本篇主要介绍一种非常好用的图标大法——图标字体(IconFont). 什么是图标字体?顾名思义,它是一种字体,只不过这个字体显示的并不是具体的文字之类的,而是各种图标. 网站上经常会用到各种图标,之前 ...
- 【Python】生成词云
import matplotlib.pyplot as plt from wordcloud import WordCloud import jieba text_from_file_with_apa ...
- SSM整合配置文件的主要内容
web.xml: <servlet> <setvlet-name>springMVC</setvlet-name> <!-- 配置前端控制器 --> & ...