动画之Evaluator
Evaluator就是通过监听器拿到当前动画对对应的具体数值,作用在于从插值器返回的数值进行转换成对应的数值.简单来说就是转换器 Evaluator返回值的类型更加动画中值决定的,所以在使用的时候注意数据类型
tv = (TextView)findViewById(R.id.tv);
findViewById(R.id.start_anim).setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
ValueAnimator animator = ValueAnimator.ofInt(0,300);
animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
public void onAnimationUpdate(ValueAnimator animation) {
int curValue = (Integer)animation.getAnimatedValue();
tv.layout(tv.getLeft(),curValue,tv.getRight(),curValue+tv.getHeight());
}
});
animator.setDuration(1000);
animator.setEvaluator(new ReverseEvaluator());
animator.start();
}
});
import android.animation.TypeEvaluator;
public class ReverseEvaluator implements TypeEvaluator<Integer> {
public Integer evaluate(float fraction, Integer startValue, Integer endValue) {
int startInt = startValue;
return (int)(endValue - fraction * (endValue - startInt));
}
}
tv = (TextView)findViewById(R.id.tv);
findViewById(R.id.start_anim).setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
ValueAnimator animator = ValueAnimator.ofInt(0xffffff00,0xff0000ff);
animator.setEvaluator(new ArgbEvaluator());//颜色值过滤转换
animator.setDuration(3000); animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
public void onAnimationUpdate(ValueAnimator animation) {
int curValue = (Integer) animation.getAnimatedValue();
tv.setBackgroundColor(curValue);
}
}); animator.start();
}
tv = (TextView)findViewById(R.id.tv);
findViewById(R.id.start_anim).setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
ValueAnimator animator = ValueAnimator.ofObject(new CharEvaluator(), new Character('A'), new Character('Z'));
animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
public void onAnimationUpdate(ValueAnimator animation) {
char text = (Character) animation.getAnimatedValue();
tv.setText(String.valueOf(text));
}
});
animator.setDuration(10000);
animator.setInterpolator(new AccelerateInterpolator());
animator.start();
}
});
抛物动画
ballImg = (ImageView) findViewById(R.id.ball_img);
findViewById(R.id.start_anim).setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
WindowManager wm = (WindowManager) getSystemService(Context.WINDOW_SERVICE);
int width = wm.getDefaultDisplay().getWidth();
int height = wm.getDefaultDisplay().getHeight();
ValueAnimator animator = ValueAnimator.ofObject(new FallingBallEvaluator(),new Point(0,0),new Point(width*2/3,height*2/3));
animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
public void onAnimationUpdate(ValueAnimator animation) {
mCurPoint = (Point) animation.getAnimatedValue();
ballImg.layout(mCurPoint.x, mCurPoint.y, mCurPoint.x + ballImg.getWidth(), mCurPoint.y + ballImg.getHeight());
}
});
animator.setDuration(2000);
animator.start();
}
});
public class FallingBallEvaluator implements TypeEvaluator<Point> {
private Point point = new Point();
public Point evaluate(float fraction, Point startValue, Point endValue) {
point.x = (int)(startValue.x + fraction *(endValue.x - startValue.x));
if (fraction*2<=1){
point.y = (int)(startValue.y + fraction*2*(endValue.y - startValue.y));
}else {
point.y = endValue.y;
}
return point;
}
}
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<solid android:color="#ff0000"/>
</shape>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_gravity="center"
tools:context="com.loaderman.customviewdemo.MainActivity"> <ImageView
android:id="@+id/ball_img"
android:layout_width="50dp"
android:layout_height="50dp"
android:src="@drawable/cicle"/> <Button
android:id="@+id/start_anim"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="开始动画"/> </LinearLayout>
动画之Evaluator的更多相关文章
- android.animation(2) - ValueAnimator的 Interpolator 和 Evaluator
一.插值器 插值器,也叫加速器:有关插值器的知识,我在<Animation动画详解(二)——Interpolator插值器>中专门讲过,大家可以先看看这篇文章中各个加速器的效果.这里再讲一 ...
- android.animation(5) - PropertyValuesHolder与Keyframe(转)
前几篇给大家讲了ValueAnimator.ObjectAnimator的知识,讲解了它们ofInt(),ofFloat(),ofObject()函数的用法.细心的同学可能会注意到,ValueAnim ...
- [转]Android自定义控件三部曲系列完全解析(动画, 绘图, 自定义View)
来源:http://blog.csdn.net/harvic880925/article/details/50995268 一.自定义控件三部曲之动画篇 1.<自定义控件三部曲之动画篇(一)—— ...
- Android属性动画源代码解析(超详细)
本文假定你已经对属性动画有了一定的了解,至少使用过属性动画.下面我们就从属性动画最简单的使用开始. ObjectAnimator .ofInt(target,propName,values[]) .s ...
- Android Animation(动画)
前言 Android 平台提供实现动画的解决方案(三种) 一.3.0以前,android支持两种动画: (1)Frame Animation:顺序播放事先做好的图像,与gif图片原理类似,是一种逐帧动 ...
- Android之动画的学习(转载)
Android动画学习笔记-Android Animation 3.0以前,android支持两种动画模式,tween animation,frame animation,在android3.0中 ...
- Android Property Animation动画
3.0以前,android支持两种动画模式,tween animation,frame animation,在android3.0中又引入了一个新的动画系统:property animation,这三 ...
- Android动画学习笔记-Android Animation
Android动画学习笔记-Android Animation 3.0以前,android支持两种动画模式,tween animation,frame animation,在android3.0中 ...
- 安卓开发_浅谈Android动画(四)
Property动画 概念:属性动画,即通过改变对象属性的动画. 特点:属性动画真正改变了一个UI控件,包括其事件触发焦点的位置 一.重要的动画类及属性值: 1. ValueAnimator 基本属 ...
随机推荐
- Windows Server 2008搭建单域环境
前言 一个典型的单域环境由主机,DC(Domain Controller域控制器).DNS服务器组成.DNS.DC都可以有多个,以实现负载均衡和容错 域中的计算机通过DNS解析域控制器,然后向域控制器 ...
- 基于ELK的日志分析、存储、展示
原文:https://blog.51cto.com/11134648/2163789 ELK简介 ELK是一套完整的日志解决方案,由ElasticSearch.Logstash. Kibana这三款开 ...
- ui自动化测试 SeleniumBase
ui自动化 SeleniumBase SeleniumBase是一个自动化web测试框架,它的设计pyse相似,基于selenium和unittest封装的框架,api多,支持命令行多参数执行 文档地 ...
- <你们都是魔鬼吗>第二次团队作业:团队项目选题
第二次团队作业:团队项目选题 项目 内容 这个作业属于哪个课程 任课教师博客主页链接 这个作业的要求在哪里 作业链接地址 团队名称 你们都是魔鬼吗 作业学习目标 任务1: 团队初选项目可行性自评,使用 ...
- vuex 随笔
vuex刷新数据消失问题: 在项目的入口页面(App.vue)里添加监听刷新事件: 或者使用插件:npm install vuex-persistedstate --save
- Linux - 网络配置( CentOS 64 )
终于..今天我终于将linux的网络调试出来了,虽然之前看了一大堆教程,每一个都是一样的步骤,但是,在我这就是弄不好,所以经过不断尝试的我,今天发一个自己配置好的步骤,唉,太痛苦了. - 对了补充一句 ...
- 57、springmvc-整合
57.springmvc-整合 57.1 创建Spring MVC Annotation项目 <?xml version="1.0" encoding="UTF-8 ...
- PostgreSQL 慢查询SQL语句跟踪
示例:启用 SQL 跟踪PostgreSQL 日志支持的输出格式有 stderr(默认), csvlog , syslog 一般的错误跟踪,只需在配置文件 [postgresql.conf]简单设置几 ...
- span标签
<span>在行内定义一个区域,也就是一行内可以被<span>划分成好几个区域,从而实现某种特定效果.<span>本身没有任何属性. <span> 与& ...
- PHP全栈学习笔记32
<?php $i = 0; do { echo $i; } while ($i > 0); ?> for (表达示1; 表达示2; 表达示3){ 需要执行的代码段 } <?ph ...