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 ...
随机推荐
- Tips4:把 Inspector面板转换为Debug模式
你知道 Inspector 的调试(debug)模式吗? 当debug模式打开后, Inspector将会把游戏物体所有的属性都显示出来,包括公有(public)和私有(private)变量. 例如, ...
- 标志数在wordcount程序中的应用与拓展
wordcount程序要求测出文本中的单词数,字符数和行数. 设计思路: 将文件读入,逐字检测,检测到空格单词数加一,检测到回车行数单词数加一,如果既不是回车也不是空格则说明是字符,字符数加一 编程时 ...
- Tools - 常用搜索引擎命令
site 用来查询网站收录量. 比如site:http://www.cnblogs.com/ inurl 查URL中包含的元素,比如inurl:bbs ,搜索出URL包含bbs的页面. 常用的inur ...
- node debug包
'use strict'; var debug = require('debug')('http') , http = require('http') , name = 'My App'; // fa ...
- css实现高度不固定的div元素模块在页面中水平垂直居中
<!DOCTYPE html><html> <head> <title>Laravel</title> <link ...
- [Architect] Abp 框架原理解析(1) Module
本节目录 Abp介绍 Abp源码分析 代码实现 Abp介绍 学习了一段时间的Abp,领略了一下前辈的架构.总结还是SOLID,降低耦合性. 虽然从架构上说甚至不依赖于DI框架,但实际上在基础框架中还是 ...
- Scrum团队成立
1.团队名称:瘦子不吃肥肉 目标:学习更多,了解更多! 口号:加油 团队照: 2.角色分配: 产品负责人:卓嘉炜 http://www.cnblogs.com/luoliuxi/ Scr ...
- CSS布局 -- 左右定宽,中间自适应
左右定宽,中间自适应 有几种方法可以实现 改变窗口大小看看? 方案一: 左右设置绝对定位,定宽,中间设置margin-left margin-right 查看 demo <!DOCTYPE h ...
- dp --- Codeforces 245H :Queries for Number of Palindromes
Queries for Number of Palindromes Problem's Link: http://codeforces.com/problemset/problem/245/H M ...
- SystemMenu类的用法
先声明对象以及相应常数: //SystemMenu对象 private SystemMenu m_systemMenu = null; // ID 常数定义 (可变,只要不与系统冲突即可) priva ...