animation of android (3)
视图动画,只有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)的更多相关文章
- animation of android (1)
android把动画的模式分为:property animation,view animation,drawable animation. view animation:给出动画的起止状态,并且通过一 ...
- animation of android (2)
android Interpolator 首先是android系统提供的变换方式: 这些方式将转载一篇文章: 转: http://www.cnblogs.com/mengdd/p/3346003.ht ...
- animation of android (4)
TimeAnimator: 与objectAminator不同,它反馈的时间间隔.也就是说TimeAnimator不产生实际的动画效果,他反馈的时间间隔和时间值. 而你并不关心 interpolate ...
- Android Animation动画实战(二):从屏幕底部弹出PopupWindow
在这篇文章之前,我已经陆陆续续写了几篇博客,介绍了Android Animation是如何使用的,有还不明白的,可以点击查看: 1. Android Animation动画详解(一): 补间动画 2. ...
- Android(java)学习笔记207:开源项目使用之gif view
1. 由于android没有自带的gif动画,我在Android(java)学习笔记198:Android下的帧动画(Drawable Animation) 播客中提到可以使用AnimationVie ...
- Android(java)学习笔记150:开源项目使用之gif view
1. 由于android没有自带的gif动画,我在Android(java)学习笔记198:Android下的帧动画(Drawable Animation) 播客中提到可以使用AnimationVie ...
- [Android]使用Kotlin开发Android(二)
以下内容为原创,欢迎转载,转载请注明 来自天天博客:http://www.cnblogs.com/tiantianbyconan/p/4829007.html [TOC] 使用Kotlin+OkHtt ...
- Android(java)学习笔记267:Android线程池形态
1. 线程池简介 多线程技术主要解决处理器单元内多个线程执行的问题,它可以显著减少处理器单元的闲置时间,增加处理器单元的吞吐能力. 假设一个服务器完成一项任务所需时间为:T1 创建线程时间, ...
- Android(java)学习笔记71:生产者和消费者之等待唤醒机制
1. 首先我们根据梳理我们之前Android(java)学习笔记70中关于生产者和消费者程序思路: 2. 下面我们就要重点介绍这个等待唤醒机制: (1)第一步:还是先通过代码体现出等待唤醒机制 pac ...
随机推荐
- weblogic集群中获取jndi的方式
# The following example specifies a list of WebLogic Servers using the same port: ht.put(Context.PRO ...
- 解决debian中脚本无法使用source的问题
#!/bin/sh source scripts/common.sh 现象: shell脚本中source aaa.sh时提示 source: not found 原因: ls -l `which s ...
- sizeof()用法汇总【转载】
转载自:http://www.cnblogs.com/chengxin1982/archive/2009/01/13/1374575.html 参考:http://blog.csdn.net/free ...
- HMM 自学教程(二)生成模型
本系列文章摘自 52nlp(我爱自然语言处理: http://www.52nlp.cn/),原文链接在 HMM 学习最佳范例,这是针对 国外网站上一个 HMM 教程 的翻译,作者功底很深,翻译得很精彩 ...
- 如何单独启动wamp 中自带的MySQL
前言:Wamp集成了Apache.MySQL和PHP环境.使用Wamp进行网站开发,是很多网站开发爱好者的选择.同时,其集成的MySQL服务,也常被用于MySQL的开发.这个时候我们只是想启动MySQ ...
- http与websocket(基于SignalR)两种协议下的跨域基于ASP.NET MVC--竹子整理
这段时间,项目涉及到移动端,这就不可避免的涉及到了跨域的问题.这是本人第一次接触跨域,有些地方的配置是有点麻烦,导致一开始的不顺. 至于websocket具体是什么意义,用途如何:请百度. 简单说就是 ...
- 数论 - 组合数学 + 素数分解 --- hdu 2284 : Solve the puzzle, Save the world!
Solve the puzzle, Save the world! Problem Description In the popular TV series Heroes, there is a ta ...
- Orleans 之 监控工具的使用
这一节,我们来说说orleans 中的几个实用工具,OrleansHost.OrleansCounterControl.OrleansManager.ClientGenerator. 1.Orlean ...
- Oracle Fusion Applications (11.1.8) Media Pack and Oracle Application Development Framework 11g (11.1.1.7.2) for Microsoft Windows x64 (64-bit)
Oracle Fusion Applications (11.1.8) Media Pack for Microsoft Windows x64 (64-bit) 重新搜索 常见问题 提示 ...
- PHP验证邮箱地址代码
PHP验证邮箱代码: function isEmail($email) { return strlen($email) > 6 && preg_match("/^[\w ...