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 ...
随机推荐
- 0x00411202指令引用的0x00000000内存该内存不能为read错误,怎么解决
0X000000该内存不能为read的解决方法 出现这个现象有方面的,一是硬件,即内存方面有问题,二是软件,这就有多方面的问题了. 一.先说说硬件问题,主要方面是: 1.内存条坏了 更换内存条 2.双 ...
- JavaScript 正则表达式提取感兴趣的字符串
var tdid="gov_sslim"; var reg=/(\w+)lim/; var name=tdid.match(reg); console.log(name[1]); ...
- css居中学习笔记
css居中学习笔记 一.水平居中 以下面的代码为例: <body> <div class="parent"> <div class="chi ...
- 重构第5天:提升字段(Pull Up Field)
理解:提升字段和前面讲解的方法提公很类似,可以说方式都是一样的.就是把继承类中经常用到的字段,提出来 放到基类中,达到通用的目的.提高代码重用性和可维护性. 详解:如下重构前的代码: using Sy ...
- 【原创随笔】Sql2008 R2 做CQRS小结
1.做数据同步,订阅服务器只要把数据库建好就可以了,至于表和存储过程以及其它的都不管,订阅的时候会自动创建这些信息. 2.选择事务发布(如果同步表,表至少要带主键,不然不能选择) 3.在发布的时候,用 ...
- Identity标识列
SQL Server中,经常会用到Identity标识列,这种自增长的字段操作起来的确是比较方便.但它有时还会带来一些麻烦. 示例一 :当表中被删除了某些数据的时候,自增长列的编号就不再是一个连线的数 ...
- alter语法的简单的使用
用alter语法来新增列名,修改列名,删除列
- strtr对用户输入的敏感词汇进行过滤
/** * 过滤用户输入的基本数据,防止script攻击 * * @access public * @return string */ function compile_str($str) { $ar ...
- [python拾遗]列表
python列表拾遗 1.列表可以修改,使用 ‘+’ 将一个新列表附加在原列表的尾部: >>> a = [1,'a'] >>> b = a + [2,'b'] &g ...
- 时间复杂度&空间复杂度
时间复杂度 参考链接: http://univasity.iteye.com/blog/1164707 空间复杂度 http://blog.csdn.net/booirror/article/deta ...