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 ...
随机推荐
- 在Asp.Net MVC中使用ModelBinding构造Array、List、Collection以及Dictionary
在asp.net mvc中,我们可以在html表单中使用特定的格式传递参数,从而通过model binder构造一些集合类型. 第一种方式 public ActionResult Infancy(Pe ...
- Java读取Excel文件的几种方法
Java读取 Excel 文件的常用开源免费方法有以下几种: 1. JDBC-ODBC Excel Driver 2. jxl.jar 3. jcom.jar 4. poi.jar 简单介绍: 百度文 ...
- 实现java 中 list集合中有几十万条数据,每100条为一组取出
解决"java 中 list集合中有几十万条数据,每100条为一组取出来如何实现,求代码!!!"的问题. 具体解决方案如下: /** * 实现java 中 list集合中有几十万条 ...
- LeetCode - 31. Next Permutation
31. Next Permutation Problem's Link ---------------------------------------------------------------- ...
- 二维KMP - 求字符矩阵的最小覆盖矩阵 - poj 2185
Milking Grid Problem's Link:http://poj.org/problem?id=2185 Mean: 给你一个n*m的字符矩阵,让你求这个字符矩阵的最小覆盖矩阵,输出这个最 ...
- 加密–RSA前端与后台的加密&解密
1. 前言 本问是根据网上很多文章的总结得到的. 2. 介绍 RSA加密算法是一种非对称加密算法. 对极大整数做因数分解的难度决定了RSA算法的可靠性.换言之,对一极大整数做因数分解愈困难,RSA算法 ...
- jquery实现全选功能
主要是模拟一些网页中的表格实现全选功能. <form> 你爱好的运动是: <input type="checkbox" id="Check" ...
- csharp: Export or Import excel using NPOI
excel 2003: using System; using System.Collections.Generic; using System.ComponentModel; using Syste ...
- java.lang.NullPointerException org.apache.jsp.WEB_002dINF.pages.imagecheck.test_jsp._jspInit(test_jsp.java:22)的原因
HTTP Status 500 - type Exception report message description The server encountered an internal error ...
- 【Effective Java】2、构造参数过多的时候
package cn.xf.cp.ch02.item2; /** * * 功能:当我们的构造参数有很多,超出可控范围的时候,用build模式 时间:下午8:25:05 文件:NutritionFact ...