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的更多相关文章

  1. Android Animation 动画Demo(Frame帧动画)

    上一页介绍Animation动画第一:Tween吐温动画. 本文介绍了以下Animation也有动画的形式:Frame帧动画. Frame动画是一系列照片示出的顺序按照一定的处理,和机制,以放电影很阶 ...

  2. android之frame动画详解

    上一篇我们说了android中的tween动画,这一篇我们说说frame动画,frame动画主要是实现了一种类似于gif动画的效果,就是多张图按预先设定好的时间依次连续显示. 新建一个android项 ...

  3. 我的Android进阶之旅------>Android之动画之Frame Animation实例

    ============================首先看看官网上关于Frame animation的介绍================================ 地址:http://de ...

  4. Android 动画具体解释Frame动画 (Drawable Animation)

    Frame动画像gif画画,通过一些静态的图片,以实现动画效果. Android sdk该AnimationDrawable就是专门针对Frame动画,当然Frame动画也可在java代码或者xml中 ...

  5. android 自定义动画

    android自定义动画注意是继承Animation,重写里面的initialize和applyTransformation,在initialize方法做一些初始化的工作,在applyTransfor ...

  6. Frame动画实战

    Android动画分为Tween动画和Frame动画,Tween动画主要包括图片的放大缩小.旋转.透明度变化.移动等等操作:Frame动画则简单得多了,就是把一张张的图片连续播放产生动画效果. 本节主 ...

  7. 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 ...

  8. Android的动画

    一.动画类型 Android的animation由四种类型组成:alpha.scale.translate.rotate XML配置文件中 alpha 渐变透明度动画效果 scale 渐变尺寸伸缩动画 ...

  9. Android View动画

    Animation TypeEvaluator View的animate方法 ValueAnimator ObjectAnimator AnimatorSet 使用xml来创建动画 animation ...

随机推荐

  1. Code Signal_练习题_alphabeticShift

    Given a string, replace each its character by the next one in the English alphabet (z would be repla ...

  2. js 下拉加载

    // 下拉加载    var clientHeight = $(window).height() //当前可视的页面高度    console.log(clientHeight) //滚动条到页面底部 ...

  3. enum 的使用方法(java)

    作者QQ:1095737364    QQ群:123300273     欢迎加入! enum很像特殊的class,实际上enum声明定义的类型就是一个类.而这些类都是类库中Enum类的子类(java ...

  4. element-ui Steps步骤条组件源码分析整理笔记(九)

    Steps步骤条组件源码: steps.vue <template> <!--设置 simple 可应用简洁风格,该条件下 align-center / description / ...

  5. ionic之angular1.X缓存问题解决

    众所周知ionic的angular1.X解决缓存的问题有: 1.在app.js里面修改:默认是true,设置了缓存 .state('tab.msg-main', { url: '/msg-main', ...

  6. 用JS实现控制浏览器F12与右键功能

    本文出至:新太潮流网络博客 用JS实现控制浏览器F12与右键功能,防止恶意窃取代码,或其他直接复制进去就好 //禁用右键 document.oncontextmenu = function () { ...

  7. 表的垂直拆分和水平拆分-zz

    https://www.kancloud.cn/thinkphp/mysql-design-optimalize/39326 http://www.cnblogs.com/nixi8/tag/mysq ...

  8. MSSQL在线文件还原脚本

    在线文件还原:如果比较大的MSSQL数据库的损坏只是集中在其中某一个文件或者文件组上,使用在线文件还原技术,只是把坏掉的数据文件或者文件组重建,能节约很多时间.以下是测试脚本(假设损坏的文件时Trn0 ...

  9. Qt与PyQT中设置ToolBar在AllowedArea的显示

    因为个人对传统的软件GUI界面不是太喜欢,最近又在学习Qt和PyQt5,所以就有了设置ToolBar在窗口的不同地方的想法,经过浪里淘沙,最终在Qt官网里找到了,原来再添加toolBar的时候是由设置 ...

  10. Log4Net记录到文件

    将这篇文章的配置文件中的log4net节点下的内容替换成下面的 https://www.cnblogs.com/RambleLife/p/9165248.html <log4net debug= ...