Android动画分为Tween动画和Frame动画,上一节通过一个实例介绍了Frame动画,本节将介绍Tween动画。Tween可以把对象进行缩小、放大、旋转和渐变等操作。
Tween动画有四个主要的实现,下面分别说明下:
1、AlphaAnimation:渐变动画,主要控制透明度变化动画类,常使用AlphaAnimation(float fromAlpha, float toAlpha)来构造;
fromAlpha:动画开始时的透明度(取值范围为0.0到1.0);
toAlpha:动画结束时的透明度;
2、ScaleAnimation:主要控制尺度变化的动画类,常使用ScaleAnimation(float fromX, float toX, float fromY, float toY, int pivotXType, float pivotXValue, int pivotYType, float pivotYValue)来构造;
fromX:动画开始X坐标上的伸缩尺度;
toX:动画结束X坐标上的伸缩尺度;
fromY:动画开始Y坐标上的伸缩尺度;
toY:动画结束Y坐标上的伸缩尺度;
pivotXType:X坐标上的伸缩模式,取值有:Animation.ABSOLUTE, Animation.RELATIVE_TO_SELF, Animation.RELATIVE_TO_PARENT;
pivotXValue:X坐标上的伸缩值;
pivotYType:Y坐标上的伸缩模式,取值有:Animation.ABSOLUTE, Animation.RELATIVE_TO_SELF, Animation.RELATIVE_TO_PARENT;
pivotYValue:Y坐标上的伸缩值;
3、TranslateAnimation:主要控制位置变换的动画实现类,常使用TranslateAnimation(float fromXDelta, float toXDelta, float fromYDelta, float toYDelta)来构造;
fromXDelta:动画开始的X坐标;
toXDelta:动画结束的X坐标;
fromYDelta:动画开始的Y坐标;
toYDelta:动画结束的Y坐标;
4、RotateAnimation:主要控制旋转的动画实现类,常使用RotateAnimation(float fromDegrees, float toDegrees, int pivotXType, float pivotXValue, int pivotYType, float pivotYValue)来构造;
fromDegrees:旋转开始角度;
toDegrees:旋转结束角度;
pivotXType, pivotXValue, pivotYType, pivotYValue与尺度变化动画ScaleAnimation类似;
下面以一个实例来进行这些动画。
1、加入将要进行动画变化的MM图片(为了避免侵犯他人肖像权,这次的MM和上次的桌面背景不一样,这个MM没有头像的):
2、创建Layout布局XML配置tween.xml文件: 
<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout xmlns:apk="http://schemas.android.com/apk/res/android" apk:orientation="vertical" apk:layout_width="fill_parent" apk:layout_height="fill_parent">
<!-- 动画MM -->
<ImageView apk:id="@+id/TweenMM" apk:src="@drawable/tween" apk:layout_width="wrap_content" apk:layout_height="wrap_content"/>

<!-- 动画控制按钮 -->
<LinearLayout apk:layout_weight="1" apk:orientation="horizontal" apk:layout_width="fill_parent" apk:layout_height="wrap_content">
<Button apk:text="ScaleAnim" apk:layout_weight="1" apk:layout_width="fill_parent" apk:layout_height="wrap_content" apk:onClick="onBtnScaleAnimClick"/>
<Button apk:text="AlphaAnim" apk:layout_weight="1" apk:layout_width="fill_parent" apk:layout_height="wrap_content" apk:onClick="onBtnAlphaAnimClick"/>
</LinearLayout>
<LinearLayout apk:layout_weight="1" apk:orientation="horizontal" apk:layout_width="fill_parent" apk:layout_height="wrap_content">
<Button apk:text="TranslateAnim" apk:layout_weight="1" apk:layout_width="wrap_content" apk:layout_height="wrap_content" apk:onClick="onBtnTranslateAnimClick"/>
<Button apk:text="RotateAnim" apk:layout_weight="1" apk:layout_width="wrap_content" apk:layout_height="wrap_content" apk:onClick="onBtnRotateAnimClick"/>
</LinearLayout>
</LinearLayout>

一张图片和4个按钮,这4个按钮就是控制图片动画的。
3、对于每个动画,我们都以一个XML配置文件来设置各自动画的属性。
AlphaAnimation(tween_alpha.xml)的配置文件内容:

<?xml version="1.0" encoding="UTF-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<alpha android:fromAlpha="0.1" android:toAlpha="1.0" android:duration="5000" />
</set>

android:duration指示该动画持续的时间,以毫秒为单位。
RotateAnimation(tween_rotate.xml)的配置文件内容:
<?xml version="1.0" encoding="UTF-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<rotate android:fromDegrees="0" android:toDegrees="360" android:pivotX="50%" android:pivotY="50%" android:duration="5000" />
</set>
ScaleAnimation(tween_scale.xml)的配置文件内容:
<?xml version="1.0" encoding="UTF-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<scale android:fromXScale="0.0" android:toXScale="1.0" android:fromYScale="0.0" android:toYScale="1.0" android:pivotX="50%" android:pivotY="50%" android:duration="5000" />
</set>
TranslateAnimation(tween_translate.xml)的配置文件内容:
<?xml version="1.0" encoding="UTF-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate android:fromXDelta="10" android:toXDelta="100" android:fromYDelta="10" android:toYDelta="100" />
</set>
4、Activity界面类:

/*** Copyright (c) 2004-2011 All Rights Reserved.*/
package com.aboy.android.study.animation;import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;import com.aboy.android.study.R;/*** 通过XML配置文件的方式实现Tween动画** @author obullxl@gmail.com* @version $Id: TweenXMLActivity.java, v 0.1 2011-6-11 下午01:36:39 oldbulla Exp $*/
public class TweenXMLActivity extends Activity {public static final String TAG = "TweenActivity";// 动画图片private ImageView          tweenMM;/** * @see android.app.Activity#onCreate(android.os.Bundle)*/public void onCreate(Bundle cycle) {super.onCreate(cycle);super.setContentView(R.layout.tween);// 取得动画图片this.tweenMM = (ImageView) super.findViewById(R.id.TweenMM);}/*** 按钮:尺寸变化动画*/public void onBtnScaleAnimClick(View view) {// 动画开始this.doStartAnimation(R.anim.tween_scale);}/*** 按钮:渐变动画*/public void onBtnAlphaAnimClick(View view) {// 动画开始this.doStartAnimation(R.anim.tween_alpha);}/*** 按钮:位置变化动画*/public void onBtnTranslateAnimClick(View view) {// 动画开始this.doStartAnimation(R.anim.tween_translate);}/*** 按钮:旋转动画*/public void onBtnRotateAnimClick(View view) {// 动画开始this.doStartAnimation(R.anim.tween_rotate);}/*** 开始动画*/private void doStartAnimation(int animId) {// 加载动画Animation animation = AnimationUtils.loadAnimation(this, animId);// 动画开始this.tweenMM.startAnimation(animation);}}

使用AnimationUtils类,可以非常方便的构造动画类;
开始动画,只要ImageView.startAnimation即可。 

转载于:https://www.cnblogs.com/obullxl/archive/2011/06/13/android-animation-tween-lady.html

Android动画之Tween动画实战相关推荐

  1. 【Android】两种动画介绍(Tween动画、Frame动画)

    Android中的动画类型有两种,一种是Tween动画.还有一种是Frame动画.Tween动画,这种实现方式可以使视图组件移动.放大.缩小以及产生透明度的变化;另一种Frame动画,传统的动画方法, ...

  2. android 同根动画_android 动画系列 (1) - tween 动画(view动画)

    这是我这个系列的目录,有兴趣的可以看下: android 动画系列 - 目录 tween 动画早些时候我们也叫补间动画(我也不知道为啥),现在也有叫 view 动画的.tween动画是2.X 时代的产 ...

  3. Android动画之Tween Animation

    Android动画里边主要分成两大类:一个是Frame动画,另一类则是Tween动画. Tween动画是操作某个控件让其展现出旋转.渐变.移动.缩放的这么一种转换过程,我们成为补间动画.我们可以以XM ...

  4. Android 动画分析之Tween动画分析

    前言: 我们选择了android开发或ios开发,是不是见到不错的app,就想看看他们的一些动画效果,交互体验,以及一些有创意的功能.今天我们就来一起学习讲解android中的动画,以及动画原理,以便 ...

  5. Android工程师面试宝典面试实战试题详解01

    1. 什么是Activity? 四大组件之一,一般的,一个用户交互界面对应一个activity setContentView() ,// 要显示的布局 , activity 是Context的子类,同 ...

  6. 【Android动画】之Tween动画 (渐变、缩放、位移、旋转)

    Android 平台提供了两类动画. 一类是Tween动画,就是对场景里的对象不断的进行图像变化来产生动画效果(旋转.平移.放缩和渐变). 第二类就是 Frame动画,即顺序的播放事先做好的图像,与g ...

  7. android 左移动画_Android研究院之游戏开发Tween动画的实现(十九)

    今天和大伙讨论一下Android开发中的Tween动画的实现.首先它和上一章我们讨论的Frame动画同属于系统提供的绘制动画的方法.Tween动画主要的功能是在绘制动画前设置动画绘制的轨迹,包括时间, ...

  8. 详解Android动画之Tween Animation

    前面讲了动画中的Frame动画,今天就来详细讲解一下Tween动画的使用. 同样,在开始实例演示之前,先引用官方文档中的一段话: Tween动画是操作某个控件让其展现出旋转.渐变.移动.缩放的这么一种 ...

  9. Android自定义控件开发入门与实战(7)SVG动画,android底层架构

    move to (50,23) line to(100,25) 而坐标并不是用width和height的坐标,而是viewportWidth和viewportHeight的坐标,(50,23)中50表 ...

最新文章

  1. 如何去除table的边框_如何擦玻璃,这些擦玻璃知识很实用
  2. java 下载文件文件名_java – 从http下载文件中检索文件名
  3. 变频器端子阻抗3k_PLC与变频器连接问题分析
  4. 反馈电路中相位补偿,到底是什么鬼?
  5. Qt实现界面的窗口的局部动态添加并布局
  6. __builtin_expect提高运行效率
  7. 测试用例集-8.公交卡测试用例
  8. 【论文笔记】HyperFace: ADeep Multi-task Learning Framework for Face Detection
  9. 变形监测与数据处理复习总结
  10. 微信小程序引入下载至本地的iconfont图标
  11. LoadRunner压力测试:测试报告结果分析
  12. 组合逻辑电路:一位全减器设计
  13. 乔治城大学计算机gre,2016年美国乔治城大学GRE成绩要求
  14. 降本增效这九个月,爱奇艺从“穿越火线”,到“冷静增长”
  15. C++ 数据存储类型
  16. CSDN旗下,河软CSDN乐知学院免费推荐诚信、踏实的Java软件工程、Android工程师,.NET工程师,PHP工程师、IOS工程师
  17. 树莓派远程控制(kali)
  18. 远程访问如此简单,通过 ZeroTier 和 Tailscale 轻松组建虚拟局域网,实现内网穿透。
  19. 基于支持向量机的机械零件剩余寿命区间估计
  20. 镇魂街qlv格式怎么转换成mp4格式

热门文章

  1. MATLAB 图像处理函数(第六章)(获取图像矩形像素的运用)
  2. 用CSS写出一个下拉菜单小箭头
  3. angular4 php,Angular4中常用管道实例详解
  4. git 代码强行提交
  5. python-面向对象
  6. ionic一些常见问题及方法
  7. 两种富文本编辑器-ckeditor和ueditor
  8. Apache+php5
  9. 打印下标iOS 6-字面量
  10. 也谈表达式分析和计算