视图动画,只有view可以使用。

在android3.0以后,属性动画。

ValueAnimation 可以记录属性变化的过程,所以他的对象是任何object。

所以ValueAnimation 的真正目的就是对object的某个值做一系列根据setInterpolator的值变化函数。

而ValueAnimation 有AnimatorUpdateListener的回调,以每个10ms的间隔,反馈随着时间的变化值。

具体代码如下:

package com.joyfulmath.animatatorsamples;

import android.animation.ValueAnimator;
import android.animation.ValueAnimator.AnimatorUpdateListener;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Paint.Align;
import android.graphics.Paint.FontMetrics;
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;
import android.view.animation.BounceInterpolator; public class ValueAnimationView extends View { private static final String TAG = "ValueAnimationView";
private Context mContext = null;
private Paint mPaint = null;
private float mX = 0;
float topY = 0;
private ValueAnimator mValueAnimator = null;
public ValueAnimationView(Context context) {
this(context, null);
} public ValueAnimationView(Context context, AttributeSet attrs) {
this(context, attrs, 0);
} public ValueAnimationView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
Log.d(TAG, "ValueAnimationView");
mContext = context;
} @Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
Log.d(TAG, "onDraw:mX\t"+mX);
canvas.drawColor(0xffffff00);
canvas.save();
canvas.translate(0, 0);
canvas.drawText(TAG, mX, mX-topY, mPaint);
canvas.restore();
} @Override
protected void onAttachedToWindow() {
super.onAttachedToWindow();
Log.d(TAG, "onAttachedToWindow");
mPaint = new Paint();
mPaint.setTextSize(18);
mPaint.setTextAlign(Align.LEFT);
mPaint.setColor(0xffff0000);
mPaint.setAntiAlias(true);
FontMetrics fontMetrics = mPaint.getFontMetrics();
topY = fontMetrics.top;
float ascentY = fontMetrics.ascent;
float descentY = fontMetrics.descent;
float bottomY = fontMetrics.bottom;
Log.d(TAG, "onAttachedToWindow fontMetrics topY:" + topY
+ "\t ascentY:" + ascentY + "\t descentY:" + descentY
+ "\t bottomY:" + bottomY);
} @Override
protected void onDetachedFromWindow() {
super.onDetachedFromWindow();
} public void createAnimator()
{
if(mValueAnimator == null)
{
mValueAnimator = ValueAnimator.ofFloat(0.0f, 50.0f);
mValueAnimator.setDuration(1000);
mValueAnimator.setInterpolator(new BounceInterpolator());
mValueAnimator.addUpdateListener(new AnimatorUpdateListener() { @Override
public void onAnimationUpdate(ValueAnimator animation) {
mX = (Float) animation.getAnimatedValue();
invalidate();
}
});
} } public void startValueAmimator()
{
Log.d(TAG, "startValueAmimator");
createAnimator();
mValueAnimator.start();
}
}

上面的代码,是自定义view,实现动画的一个基础。

关键就是每次OnDraw的时候,获取objcet动画的属性。

而触发条件就是:

            mValueAnimator.addUpdateListener(new AnimatorUpdateListener() {

                @Override
public void onAnimationUpdate(ValueAnimator animation) {
mX = (Float) animation.getAnimatedValue();
invalidate();//触发onDraw
}
});
}

所以valueObjcet的关键就是会在动画过程中改变object的属性,以此来决定如何通过这个变化来实现动画。

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

  1. animation of android (1)

    android把动画的模式分为:property animation,view animation,drawable animation. view animation:给出动画的起止状态,并且通过一 ...

  2. animation of android (2)

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

  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. [Node.js] 使用File API 异步上传文件

    原文地址:http://www.moye.me/2014/11/05/html5-filereader/ 最近在做一个网盘的项目,不出意外的涉及到大文件的上传,那么问题来了:如何实时的显示文件上传的进 ...

  2. Mysql学习笔记(十一)临时表+视图

    学习内容: 临时表和视图的基本操作... 临时表与视图的使用范围... 1.临时表   临时表:临时表,想必大家都知道这个概念的存在...但是我们什么时候应该使用到临时表呢?当一个数据库存在着大量的数 ...

  3. 内存中OLTP(Hekaton)里的事务日志记录

    在今天的文章里,我想详细讨论下内存中OLTP里的事务日志如何写入事务日志.我们都知道,对于你的内存优化表(Memory Optimized Tables),内存中OLTP提供你2个持久性(durabi ...

  4. HNU 13308 Help cupid

    Help cupid Problem's Link: http://acm.hnu.cn/online/?action=problem&type=show&id=13308&c ...

  5. 重构第7天 重命名(Rename )

    理解:重命名就是把一些函数.字段.类.参数的名称 重命名为易于理解,最好是和自身的意义相同的名称.这样更易于理解,也可以减少大量的注释,名字即含义. 详解: 这个重构方法是我经常也是最常用的一种.我们 ...

  6. C#设计模式——桥接模式(Bridge Pattern)

    一.概述在软件开发中,我们有时候会遇上一个对象具有多个变化维度.比如对汽车对象来说,可能存在不同的汽车类型,如公共汽车.轿车等,也可能存在不同的发动机,如汽油发动机.柴油发动机等.对这类对象,可应用桥 ...

  7. .NET程序的编译和运行

    程序的编译和运行,总得来说大体是:首先写好的程序是源代码,然后编译器编译为本地机器语言,最后在本地操作系统运行. 下图为传统代码编译运行过程: .NET的编译和运行过程与之类似,首先编写好的源代码,然 ...

  8. sql 执行时间

    SET STATISTICS PROFILE ON SET STATISTICS IO ON SET STATISTICS TIME ON --GO /*--你的SQL脚本开始*/SELECT * F ...

  9. java操作小技巧,遇到过的会一直更新,方便查找

    1.<c:forEach>可以循环map array List 2.操纵数组,不知道类型的情况下,不需要判断数组类型,直接用反射,arrays.Class.isArrays() 获取数组长 ...

  10. Android笔记——Android中数据的存储方式(三)

    Android系统集成了一个轻量级的数据库:SQLite,所以Android对数据库的支持很好,每个应用都可以方便的使用它.SQLite作为一个嵌入式的数据库引擎,专门适用于资源有限的设备上适量数据存 ...