android把动画的模式分为:property animation,view animation,drawable animation.

view animation:给出动画的起止状态,并且通过一定的方式来是view动起来。这个动画只能用于view。

帧动画:是给出一组图片,有drawable来展示动画变化过程。

1.tweened animation

layout:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".AnimationActivity" > <ImageView
android:id="@+id/animation_img"
android:layout_width="150dp"
android:layout_height="150dp"
android:layout_centerInParent="true"
android:src="@drawable/icon_follower" /> <LinearLayout
android:id="@+id/action_items"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="horizontal" > <Button
android:id="@+id/btn_alphaanimation"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="true"
android:text="@string/alpha_animation" /> <Button
android:id="@+id/btn_rotateanimation"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="true"
android:text="@string/rotate_animation" /> <Button
android:id="@+id/btn_scaleanimation"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="true"
android:text="@string/scale_animation" />
<Button
android:id="@+id/btn_translationanimation"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="true"
android:text="@string/scale_animation" />
</LinearLayout> </RelativeLayout>

activity:

package com.joyfulmath.animatatorsamples;

import android.os.Bundle;
import android.app.Activity;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.animation.AccelerateDecelerateInterpolator;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.view.animation.BounceInterpolator;
import android.view.animation.LinearInterpolator;
import android.view.animation.OvershootInterpolator;
import android.view.animation.RotateAnimation;
import android.view.animation.ScaleAnimation;
import android.view.animation.TranslateAnimation;
import android.widget.Button;
import android.widget.ImageView; public class AnimationActivity extends Activity implements OnClickListener{ private static final String TAG = "animatatorsamples";
Button mAlphaAnimation = null;
Button mRotateAnimation = null;
Button mScaleAnimation = null;
Button mTranslationAnimation = null;
ImageView mImage = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_animation_main);
mAlphaAnimation = (Button) this.findViewById(R.id.btn_alphaanimation);
mAlphaAnimation.setOnClickListener(this);
mRotateAnimation = (Button) this.findViewById(R.id.btn_rotateanimation);
mRotateAnimation.setOnClickListener(this); mScaleAnimation = (Button) this.findViewById(R.id.btn_scaleanimation);
mScaleAnimation.setOnClickListener(this); mTranslationAnimation = (Button) this.findViewById(R.id.btn_translationanimation);
mTranslationAnimation.setOnClickListener(this); mImage = (ImageView) this.findViewById(R.id.animation_img);
} @Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.animation, menu);
return true;
} @Override
public void onClick(View v) {
// TODO Auto-generated method stub
switch(v.getId())
{
case R.id.btn_alphaanimation:
startAlphaAnimation();
break;
case R.id.btn_rotateanimation:
startRotateAnimation();
break;
case R.id.btn_scaleanimation:
startScaleAnimation();
break;
case R.id.btn_translationanimation:
startThanslationAnimation();
break;
}
} private void startRotateAnimation() {
Log.i(TAG, "[startRotateAnimation]");
//Animation.RELATIVE_TO_SELF the center of rotate
Animation rotateaAni = new RotateAnimation(0f, 360f,Animation.RELATIVE_TO_SELF,0.5f,Animation.RELATIVE_TO_SELF,0.5f);
rotateaAni.setDuration(3000);
rotateaAni.setFillAfter(true);
rotateaAni.setInterpolator(new LinearInterpolator());
mImage.startAnimation(rotateaAni); } private void startAlphaAnimation() {
Log.i(TAG, "[startAlphaAnimation]");
AlphaAnimation alphaAni = new AlphaAnimation(1.0f, 0.5f);
alphaAni.setDuration(3000);
alphaAni.setFillAfter(true);
alphaAni.setInterpolator(new OvershootInterpolator());
alphaAni.setAnimationListener(new AnimationListener() { @Override
public void onAnimationStart(Animation arg0) {
// TODO Auto-generated method stub
Log.i(TAG, "[onAnimationStart]");
} @Override
public void onAnimationRepeat(Animation arg0) {
// TODO Auto-generated method stub
Log.i(TAG, "[onAnimationRepeat]");
} @Override
public void onAnimationEnd(Animation arg0) {
// TODO Auto-generated method stub
Log.i(TAG, "[onAnimationEnd]");
}
}); mImage.startAnimation(alphaAni);
} private void startScaleAnimation()
{
float fromX; //1.0f to 0.0f
float toX;
float fromY;
float toY;
int pivotXType; //where is the last place after scale
float pivotXValue;
int pivotYType;
float pivotYValue;
//Animation.ABSOLUTE, //the last place with X ordinate with absolute diff 20f
//Animation.RELATIVE_TO_SELF, //specified dimension to self
//Animation.RELATIVE_TO_PARENT. //specified dimension to parent move 100%=1f with diff (%parent diff)
ScaleAnimation scaleAnim = new ScaleAnimation(1.0f, 0.5f, 1.0f, 0.5f
// ,Animation.ABSOLUTE, 20f, Animation.RELATIVE_TO_PARENT,
// 2f
);
//ScaleAnimation(float fromX, float toX, float fromY, float toY) 绫讳技Animation.ABSOLUTE,涓攛,y =0;
scaleAnim.setDuration(3000);
scaleAnim.setFillAfter(true);
scaleAnim.setInterpolator(new OvershootInterpolator());
mImage.startAnimation(scaleAnim); } private void startThanslationAnimation()
{
Log.i(TAG, "[startThanslationAnimation]");
//Animation.ABSOLUTE where is the last point show place
//the start x,y ordinate is the current place with translation
TranslateAnimation anmit= new TranslateAnimation(Animation.RELATIVE_TO_PARENT,0.1f,Animation.RELATIVE_TO_PARENT,0.5f,
Animation.RELATIVE_TO_PARENT,0.2f,Animation.RELATIVE_TO_PARENT, 0.6f);
anmit.setDuration(3000);
anmit.setFillAfter(true);
anmit.setInterpolator(new BounceInterpolator());
mImage.startAnimation(anmit);
} }

animation 是一种变换动画,也就是实际的响应位置和大小并没有变化,只是视图上的变换。

这种动画变换成本低,效率高。

这些类都继承自android.view.animation.Animation

2.animationset

view视图动画组合只用是一个view对象的多种状态变换。

    /**
* Constructor to use when building an AnimationSet from code
*
* @param shareInterpolator Pass true if all of the animations in this set
* should use the interpolator associated with this AnimationSet.
* Pass false if each animation should use its own interpolator.
*/
public AnimationSet(boolean shareInterpolator) {
setFlag(PROPERTY_SHARE_INTERPOLATOR_MASK, shareInterpolator);
init();
}

如androidsdk源码所示,shareInterpolator将决定使用每个animation的interpolator

还是animationset的变换方式。

animationset的变换只能一起播放,只有通过startoffset的方式可以模拟变换的顺序。

3.android.view.animation.BaseInterpolator

变换方式:

末前支持的是:

AccelerateDecelerateInterpolator,  开始和结束变换慢,中间变换快速

AccelerateInterpolator,          开始缓慢,然后加速

AnticipateInterpolator,        变换会有一个回调,也就是先向后变换,然后按照给定关键帧的方式变换。   

AnticipateOvershootInterpolator,      An interpolator where the change starts backward then flings forward and overshoots the target value and finally goes back to the final value

BounceInterpolator,         贝叶斯曲线

CycleInterpolator,          sin曲线

DecelerateInterpolator,        减速变化

LinearInterpolator,          默认,线性变换

OvershootInterpolator,        An interpolator where the change flings forward and overshoots the last value then comes back.

PathInterpolator          5.1新功能。可以自定义变换路径方式。         

animation of android (1)的更多相关文章

  1. animation of android (2)

    android Interpolator 首先是android系统提供的变换方式: 这些方式将转载一篇文章: 转: http://www.cnblogs.com/mengdd/p/3346003.ht ...

  2. animation of android (3)

    视图动画,只有view可以使用. 在android3.0以后,属性动画. ValueAnimation 可以记录属性变化的过程,所以他的对象是任何object. 所以ValueAnimation 的真 ...

  3. animation of android (4)

    TimeAnimator: 与objectAminator不同,它反馈的时间间隔.也就是说TimeAnimator不产生实际的动画效果,他反馈的时间间隔和时间值. 而你并不关心 interpolate ...

  4. Android Animation动画实战(二):从屏幕底部弹出PopupWindow

    在这篇文章之前,我已经陆陆续续写了几篇博客,介绍了Android Animation是如何使用的,有还不明白的,可以点击查看: 1. Android Animation动画详解(一): 补间动画 2. ...

  5. Android(java)学习笔记207:开源项目使用之gif view

    1. 由于android没有自带的gif动画,我在Android(java)学习笔记198:Android下的帧动画(Drawable Animation) 播客中提到可以使用AnimationVie ...

  6. Android(java)学习笔记150:开源项目使用之gif view

    1. 由于android没有自带的gif动画,我在Android(java)学习笔记198:Android下的帧动画(Drawable Animation) 播客中提到可以使用AnimationVie ...

  7. [Android]使用Kotlin开发Android(二)

    以下内容为原创,欢迎转载,转载请注明 来自天天博客:http://www.cnblogs.com/tiantianbyconan/p/4829007.html [TOC] 使用Kotlin+OkHtt ...

  8. Android(java)学习笔记267:Android线程池形态

    1. 线程池简介  多线程技术主要解决处理器单元内多个线程执行的问题,它可以显著减少处理器单元的闲置时间,增加处理器单元的吞吐能力.     假设一个服务器完成一项任务所需时间为:T1 创建线程时间, ...

  9. Android(java)学习笔记71:生产者和消费者之等待唤醒机制

    1. 首先我们根据梳理我们之前Android(java)学习笔记70中关于生产者和消费者程序思路: 2. 下面我们就要重点介绍这个等待唤醒机制: (1)第一步:还是先通过代码体现出等待唤醒机制 pac ...

随机推荐

  1. Ladda – 把加载提示效果集成到按钮中,提升用户体验

    Ladda 是一组集成了加载提示的按钮,以弥合行动和反馈之间的时间间隔,提供更好的功能使用体验.主要用于在用户点击提交之后,向用户提供即时的反馈,让他们知道浏览器正在处用户提交的任务. 您可能感兴趣的 ...

  2. const与readonly深度分析(.NET)

    前言 很多.NET的初学者对const和readonly的使用很模糊,本文就const和readonly做一下深度分析,包括: 1. const数据类型的优势 2. const数据类型的劣势 3. r ...

  3. JS 对象属性相关--检查属性、枚举属性等

    1.删除属性 delete运算符可以删除对象的属性 delete person.age //即person不再有属性age delete person['age'] //或者这样 delete只是断开 ...

  4. C#设计模式——抽象工厂模式(Abstract Factory Pattern)

    一.概述在软件开发中,常常会需要创建一系列相互依赖的对象,同时,由于需求的变化,往往存在较多系列对象的创建工作.如果采用常规的创建方法(new),会造成客户程序和对象创建工作的紧耦合.对此,抽象工厂模 ...

  5. jQuery实现表格拖动排序

    原理就是利用mousedown.mouseover.mouseup事件实现拖动,并用Ajax实现保存结果. JS代码如下: <!--题目调序功能--> <script type=&q ...

  6. java数据库查询类

    通用查询数据库辅助类,可实现任意查询语句的查询,还可以进行多结果集查询. 类的代码: package com.hongyuan.db; import java.math.BigDecimal; imp ...

  7. vs2008不能创建C#项目的解决方法

    解决方法:1.先关闭 Visual Studio 2008 ;2.在运行中输入命令"devenv.exe /setup"3.运行 Visual Studio 2008 ,一切搞定. ...

  8. DataList分页访问FooterTemplate模板里的控件

    今天做DataList分页的时候,突然想把分页控件写在FooterTemplate模板里面,弄了很久都访问不到控件,终于发现问题所在,以下是访问FooterTemplate里控件的方法: <Fo ...

  9. 【JS复习笔记】03 继承

    关于继承 好吧,说到底JS还是原型继承的,而不是类继承.所以在这个上面要经常用到prototype去继承另一个对象. 所有的构造器函数都约定命名为首字母大写的形式,并且不以首字母大写的形式拼写任何其它 ...

  10. ValueStack值栈和ActionContext

    Struts2在OGNL之上提供的最大附加特性就是支持值栈(ValueStack),在OGNL上下文中只能有一个根对象,Struts2的值栈则允许存在许多虚拟对象. 一:值栈(ValueStack) ...