View Animation, 它显示在view向上Tween Animation

Tween动画。本质上没有变化View对象本身。只要改变它绘制

实施方式有两种。一个xml定义,直接在代码中的定义

xml定义方式:

位移动画translate

<?

xml version="1.0" encoding="utf-8"?

>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="1000"
android:fromXDelta="10"
android:fromYDelta="0"
android:toXDelta="50%"
android:toYDelta="50%p"
android:repeatCount="50"
android:repeatMode="reverse"
android:fillAfter="true">
<!-- repeatCount 动画再次反复的次数
repeatMode 这一次反转上一次的效果
fillAfter 动画结束后,view停留在动画结束时的位置 view的实际位置并没有改变
50%p 相对于父布局
50% 相对于自身
-->
</translate>

旋转动画rotate

<?xml version="1.0" encoding="utf-8"?>
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="1000"
android:fromDegrees="0"
android:toDegrees="-90"
android:pivotX="50%"
android:pivotY="50%"
android:repeatCount="50"
android:repeatMode="reverse"
android:fillAfter="true">
<!--
fromDegrees="0" 開始角度
toDegrees="-90" 结束角度
pivotX="50%" 中心点x
pivotY="50%" 中心点y
-->
</rotate>

透明度渐变动画alpha

<?

xml version="1.0" encoding="utf-8"?>
<alpha xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="1000"
android:fromAlpha="0"
android:toAlpha="1"
android:fillAfter="true"
android:repeatCount="50"
android:repeatMode="reverse" >
<!--
fromAlpha 開始的透明度 0全然透明
toAlpha 结束的透明度 1全然不透明
-->
</alpha>

缩放动画scale

<?

xml version="1.0" encoding="utf-8"?>
<scale xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="1000"
android:fromXScale="0.5"
android:fromYScale="1"
android:toXScale="3"
android:toYScale="2"
android:pivotX="50%"
android:pivotY="50%"
android:fillAfter="true"
android:repeatCount="50"
android:repeatMode="reverse" >
<!--
scale 缩放比率
-->
</scale>

动画集

<?

xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="2000"
android:fillAfter="true"
android:repeatCount="50"
android:repeatMode="reverse" > <scale
android:fromXScale="0.5"
android:fromYScale="1"
android:pivotX="50%"
android:pivotY="50%"
android:repeatCount="50"
android:repeatMode="reverse"
android:toXScale="3"
android:toYScale="2" /> <alpha
android:fromAlpha="0"
android:repeatCount="50"
android:repeatMode="reverse"
android:toAlpha="1" /> <translate
android:fromXDelta="10"
android:fromYDelta="0"
android:repeatCount="50"
android:repeatMode="reverse"
android:toXDelta="50%"
android:toYDelta="50%p" /> <rotate
android:fromDegrees="0"
android:pivotX="50%"
android:pivotY="50%"
android:repeatCount="50"
android:repeatMode="reverse"
android:toDegrees="-100" /> </set>

代码载入这些xml定义的动画

	Animation translate = AnimationUtils.loadAnimation(this, R.anim.translate);
imageview_translate.setBackground(getResources().getDrawable(R.drawable.a11));
imageview_translate.startAnimation(translate); Animation rotate = AnimationUtils.loadAnimation(this, R.anim.rotate);
imageview_rotate.setBackground(getResources().getDrawable(R.drawable.a11));
imageview_rotate.startAnimation(rotate); Animation alpha = AnimationUtils.loadAnimation(this, R.anim.alpha);
imageview_alpha.setBackground(getResources().getDrawable(R.drawable.a11));
imageview_alpha.startAnimation(alpha); Animation scale = AnimationUtils.loadAnimation(this, R.anim.scale);
imageview_scale.setBackground(getResources().getDrawable(R.drawable.a11));
imageview_scale.startAnimation(scale); Animation set = AnimationUtils.loadAnimation(this, R.anim.set);
imageview_set.setBackground(getResources().getDrawable(R.drawable.a11));
imageview_set.startAnimation(set);

纯代码创建Tween Animation

AnimationSet animationSet = new AnimationSet(true);
animationSet.addAnimation(scale);
animationSet.addAnimation(translate);
animationSet.addAnimation(alpha);
animationSet.addAnimation(rotate);
animationSet.setDuration(2000);
animationSet.setRepeatCount(50);
animationSet.setRepeatMode(Animation.RESTART);
// animationSet.setRepeatMode(Animation.REVERSE);
imageview_set.setBackground(getResources().getDrawable(R.drawable.a11));
imageview_set.startAnimation(animationSet); TranslateAnimation translateAnimation;
RotateAnimation rotateAnimation;
AlphaAnimation alphaAnimation;
ScaleAnimation scaleAnimation;
// Animation.RELATIVE_TO_SELF 相对于自身
// Animation.RELATIVE_TO_PARENT 相对于父View

设置动画监听器

	scale.setAnimationListener(new AnimationListener() {

				@Override //动画開始
public void onAnimationStart(Animation animation) { } @Override //动画反复
public void onAnimationRepeat(Animation animation) { } @Override //动画结束
public void onAnimationEnd(Animation animation) { }
});

动画插入器Interpolator

在animation的xml和代码中 能够设置动画的插入器。它用来指示动画在持续时间内的动作的速率变化

android:interpolator="@android:anim/overshoot_interpolator"OvershootInterpolator

 <!--
默认情况下:动画随着时间的推移 均匀的被应用,要改变这样的效果能够使用插入器
interpolator 设置插入器
accelerate_interpolator 相似加速度先小后大, 開始慢 后渐快 变速运动
accelerate_decelerate_interpolator 相似加速度先大后小, 先加速 后减速 变速运动 anticipate_interpolator the change starts backward then flings forward 先减(减到比開始值还小一点),后加(加到结束值)
anticipate_overshoot_interpolator 先减(减到比開始值还小一点),后加(加到比结束值还大一点。再回退到结束值)
overshoot_interpolator 直接加速到结束值。并比结束值还大一点,再回退到结束值 bounce_interpolator 反弹结束时的变化 到达结束值时一会小一会大 来回两次
cycle_interpolator 先高速从開始到结束值,再遵循正弦模式继续运动 (左右对切,上下对切)
linear_interpolator 相似加速度为0,速率不变, 匀速运动 不定义插入器时使用的默认值 -->

版权声明:本文博主原创文章,博客,未经同意不得转载。

Android Tween Animation的更多相关文章

  1. 深入Animation,在SurfaceView中照样使用Android—Tween Animation!

    第一类:Frame By Frame 帧动画( 不推荐游戏开发中使用)             所谓帧动画,就是顺序播放事先做好的图像,类似于放电影:             分析: 此种方式类似我之 ...

  2. android tween animation合集

    自己写的一些tween animation动画xml文件,可用于activity切换,图片切换动画等 http://files.cnblogs.com/zj2012zy/anim.rar

  3. android之Tween Animation

    android Tween Animation有四种,AlphaAnimation(透明度动画).ScaleAnimation(尺寸伸缩动画).TranslateAnimation(位移动画).Rot ...

  4. Android动画效果之Tween Animation(补间动画)

    前言: 最近公司项目下个版本迭代里面设计了很多动画效果,在以往的项目中开发中也会经常用到动画,所以在公司下个版本迭代开始之前,抽空总结一下Android动画.今天主要总结Tween Animation ...

  5. Android动画学习(二)——Tween Animation

    前两天写过一篇Android动画学习的概述,大致的划分了下Android Animation的主要分类,没有看过的同学请移步:Android动画学习(一)——Android动画系统框架简介.今天接着来 ...

  6. Android动画Animation之Tween用代码实现动画

    透明度动画.旋转动画.尺寸伸缩动画.移动动画 package com.javen.tween; import android.annotation.SuppressLint; import andro ...

  7. Android开发UI之补间动画-Tween Animation

    Tween Animation-补间动画 官网链接-http://developer.android.com/reference/android/view/animation/Animation.ht ...

  8. Android动画总结#补间动画(Tween Animation/View Animation) #帧动画(Frame Animation/Drawable Animation)#属性动画(PropertyAnimation)

    1.共有三种动画,英文名字多种叫法如下 第一种动画:补间动画(Tween Animation/View Animation) 四个:RotateAnimation旋转. AlphaAnimation透 ...

  9. 详解Android动画之Tween Animation

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

随机推荐

  1. Winform通用模块之流水号生成

    打算接下来的时间里把自己觉得用起来还比较好用的通用模块,在这里向大家介绍一下,如果你有更好的想法时,也希望你不吝指点. 1.数据库表及存储过程 在介绍这个通用流水号生成的模块前,我们先来看一下其相关的 ...

  2. 使用windows-SQLyog连接linux-mysql

          嘿嘿,最近又清闲了一点,重新安装了mysql去学习.   -----博客园-邦邦酱好 系统环境: 1. 主机为windows系统,安装了SQLyog. 2. 主机上还安装了虚拟机,系统为c ...

  3. 怎样从host之外连接到docker container

    启动docker的时候的指令使用 sudo docker -H tcp://0.0.0.0:4243 -H unix:///var/run/docker.sock -d & 这样就能使dock ...

  4. hdu5618 (三维偏序,cdq分治)

    给定空间中的n个点,问每个点有多少个点小于等于自己. 先来分析简单的二维的情况,那么只要将x坐标排序,那么这样的问题就可以划分为两个子问题,,这样的分治有一个特点,即前一个子问题的解决是独立的,而后一 ...

  5. 《JavaScript设计模式与开发实践》读书笔记之观察者模式

    1.观察者模式 观察者模式定义对象间的一种一对多的依赖关系,当一个对象的状态发生改变时,所有依赖于它的对象都将得到通知. JavaScript中通常采用事件模型替代传统的观察者模式 1.1 逐步实现观 ...

  6. windows phone 加速计(5)

    原文:windows phone 加速计(5) 在windows phone 中存在着加速计,我们可以利用加速计获得用户手机的状态,根据手机状态调整我们的程序,这样会更人性化:windows phon ...

  7. Bestcoder Round#45

    1001 给定数n,要我们求该数的二进制中有多少组1, 相邻的1称为1组, 直接位运算摸你即可 #include <stdio.h> #include <string.h> # ...

  8. 全部编程皆为Web编程

    原文作者:Jeff Atwood   原文链接:http://blog.codinghorror.com/all-programming-is-web-programming Michael Brau ...

  9. Effective C++规定45 额外的代码

    这部分是额外的代码博客,关键45术语思想已经实现. #include<iostream> using namespace std; template<typename T> c ...

  10. 初识google多语言通信框架gRPC系列(一)概述

    gRPC概述 3/26/2016 9:16:08 AM 目录 一.概述 二.编译gRPC 三.C#中使用gRPC 四.C++中使用gRPC 一直在寻找多平台多语言的通信框架,微软的WCF框架很强大和灵 ...