android动画笔记二

    从android3.0,系统提供了一个新的动画-property animation, 为什么系统会提供这样一个全新的动画包呢,先来看看之前的补间动画都有什么缺陷吧

1、传统的补间动画都是固定的编码,功能是固定的,扩展难度大。比如传统动画只能实现移动、缩放、旋转、淡入淡出,四种效果,如果去改变view的背景,就只能自己去实现。
2、补间动画只是改变了view的显示效果,不会真正改变view的属性,比如一个动画的点击时间,view移动到另一个地方,它的监听事件还在换来的地方。
3、传统动画不能对非view的对象进行动画操作。
这估计就是property animation出现的原因了吧,说了这些来看看android.animation里面都有什么东西吧
animator
ValueAnimator
ValueAnimator是整个动画机制当中最核心的一个类,属性动画中主要的时序引擎,如动画的时间,开始、结束属性值,ValueAnimator还负责管理动画的播放次数,播放模式,以及对动画设计监听器。

ValueAnimator anim = ValueAnimator.ofFloat(0f, 1f);  
anim.setDuration(300);  
anim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {  @Override  public void onAnimationUpdate(ValueAnimator animation) {  float currentValue = (float) animation.getAnimatedValue();  Log.d("TAG", "cuurent value is " + currentValue);  }  
});  
anim.start();

ObjectAnimator
允许你指定要进行动画的对象以及该对象的一个属性。该类会根据计算得到的新值自动更新属性。ValueAnimator是对值进行了一个平滑的动画过渡,而objectAnimator则可以直接对任意对象的属性进行动画操作。
fter(Animator anim) 将现有动画插入到传入的动画之后执行
after(long delay) 将现有动画延迟指定毫秒后执行
before(Animator anim) 将现有动画插入到传入的动画之前执行
with(Animator anim) 将现有动画和传入的动画同时执行

ObjectAnimator animator = ObjectAnimator.ofFloat(textview, "alpha", 1f, 0f, 1f);  
animator.setDuration(5000);  
animator.start();  

AnimatorSet
使动画组合到一起,并可设置组中动画的时序关系,如同时播放,有序播放或延迟播放。

ObjectAnimator moveIn = ObjectAnimator.ofFloat(textview, "translationX", -500f, 0f);  
ObjectAnimator rotate = ObjectAnimator.ofFloat(textview, "rotation", 0f, 360f);  
ObjectAnimator fadeInOut = ObjectAnimator.ofFloat(textview, "alpha", 1f, 0f, 1f);  
AnimatorSet animSet = new AnimatorSet();  
animSet.play(rotate).with(fadeInOut).after(moveIn);  
animSet.setDuration(5000);  
animSet.start();  

Interpolator
先看一下TimeInterpolator接口的定义,

public interface TimeInterpolator {  /** * Maps a value representing the elapsed fraction of an animation to a value that represents * the interpolated fraction. This interpolated value is then multiplied by the change in * value of an animation to derive the animated value at the current elapsed animation time. * * @param input A value between 0 and 1.0 indicating our current point *        in the animation where 0 represents the start and 1.0 represents *        the end * @return The interpolation value. This value can be more than 1.0 for *         interpolators which overshoot their targets, or less than 0 for *         interpolators that undershoot their targets. */  float getInterpolation(float input);  
}  

getInterpolation()方法中接收一个input参数,这个参数的值会随着动画的运行而不断变化,不过它的变化是非常有规律的,就是根据设定的动画时长匀速增加,变化范围是0到1。动画一开始input的值是0, 结束时input的值是1, 而中间值则是随着动画运行的时长在0到1之间变化。
ViewPropertyAnimator
为了方便对view的动画操作,在android3.1补充了ViewPropertyAnimator这个机制。

PropertyValuesHolder pvhX = PropertyValuesHolder.ofFloat("x", 50f);
PropertyValuesHolder pvhY = PropertyValuesHolder.ofFloat("y", 100f);
ObjectAnimator.ofPropertyValuesHolder(myView, pvhX, pvyY).start();
myView.animate().x(50f).y(100f);

为ViewGroup添加布局动画
可以在ViewGroup内,通过LayoutTransition类为布局的变化添加动画。
当一个ViewGroup中添加或者移除某一个item,或者调用了View的setVisibility方法,使得View 变得VISIBLE或者GONE的时候,在ViewGroup内部的View可以完成出现或者消失的动画。当你添加或者移除View的时候,那些剩余的View也可以通过动画的方式移动到自己的新位置。你可以通过setAnimator()方法并传递一个Animator对象,在LayoutTransition内部定义以下动画。以下是几种事件类型的常量:

APPEARING        为那些添加到父元素中的元素应用动画
CHANGE_APPEARING    为那些由于父元素添加了新的item而受影响的item应用动画
DISAPPEARING       为那些从父布局中消失的item应用动画
CHANGE_DISAPPEARING  为那些由于某个item从父元素中消失而受影响的item应用动画

你可以为这四种事件定义自己的交互动画,或者仅仅告诉动画系统使用默认的动画。
API Demos中的LayoutAnimations sample向你展示了如何为布局转换定义一个布局动画,然后将该动画设置到目标View对象上
Keyframes
由一个键值对组成,可以为动画定义某一特定时间的特定状态。每个keyframe可以拥有自己的插值器,用于控制前一帧和当前帧的时间间隔间内的动画。第一个参数为:要执行该帧动画的时间节点(elapsed time / duration),第二个参数为属性值。

Keyframe kf0 = Keyframe.ofFloat(0f, 0f);
Keyframe kf1 = Keyframe.ofFloat(.5f, 360f);
Keyframe kf2 = Keyframe.ofFloat(1f, 0f);
PropertyValuesHolder pvhRotation = PropertyValuesHolder.ofKeyframe(“rotation”, kf0, kf1, kf2);//动画属性名,可变参数
ObjectAnimator rotationAnim = ObjectAnimator.ofPropertyValuesHolder(target, pvhRotation)
rotationAnim.setDuration(5000ms);

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/389191.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

回归分析检验_回归分析

回归分析检验Regression analysis is a reliable method in statistics to determine whether a certain variable is influenced by certain other(s). The great thing about regression is also that there could be multiple variables influencing the variable of intere…

是什么样的骚操作让应用上线节省90%的时间

优秀的程序员 总会想着 如何把花30分钟才能解决的问题 在5分钟内就解决完 例如在应用上线这件事上 通常的做法是 构建项目在本地用maven打包 每次需要clean一次,再build一次 部署包在本地ide、git/svn、maven/gradie 及代码仓库、镜像仓库和云平台间 来回切换 上传部…

QQ API

QQ API设计说明书目录一、引言 31.1 编写目的 31.2 更新时间 3二、总体设计 3三、注册的系统消息 33.1 WM_QQAPI_REGISTER 33.2 WM_QQAPI_REGISTER_RESP 43.3 WM_QQAPI_AVAILABLE 4四、从设备到QQ的自定义事件 54.1 EVENT_QQAPI_SET_AUDIODEVICE …

Ubuntu 18.04 下如何配置mysql 及 配置远程连接

首先是大家都知道的老三套,啥也不说上来就放三个大招: sudo apt-get install mysql-serversudo apt isntall mysql-clientsudo apt install libmysqlclient-dev 这三步下来mysql就装好了,然后我们偷偷检查一下 sudo netstat -tap | grep mysq…

数据科学与大数据技术的案例_主数据科学案例研究,招聘经理的观点

数据科学与大数据技术的案例I’ve been in that situation where I got a bunch of data science case studies from different companies and I had to figure out what the problem was, what to do to solve it and what to focus on. Conversely, I’ve also designed case…

导致View树遍历的时机

遍历View树意味着整个View需要重新对其包含的子视图分配大小并重绘,导致重新遍历的原因主要有三个 1.视图本身内部状况变化引起重绘。 2.第二个是View树内部添加或者删除了View。 3.View本身的大小及可见性发生变化。 能引起View树重新遍历的操作,总…

什么是Hyperledger?Linux如何围绕英特尔的区块链项目构建开放平台?

访问区块链会议并关注区块链新闻时,不可避免地,您会遇到Linux基金会的Hyperledger。理解像比特币、以太坊这样的加密货币还算相对容易的,Hyperledger却不然。但如果你多研究研究,你会发现一些令人兴奋的非货币、工业区块链的应用项…

队列的链式存储结构及其实现_了解队列数据结构及其实现

队列的链式存储结构及其实现A queue is a collection of items whereby its operations work in a FIFO — First In First Out manner. The two primary operations associated with them are enqueue and dequeue.队列是项目的集合,由此其操作以FIFO(先进先出)的方…

安装

、添加一个新项目->选择类库模板->命名为DBCustomAction 2、单击项目右键->添加新项->选择安装程序类(命名为DBCustomAction.cs) 3、在 服务器资源管理器中添加->连接到 数据库->指定用户密码(选择允许保存密码)-> 数据库选择master 4、切换到DBCustomAct…

cad2016珊瑚_预测有马的硬珊瑚覆盖率

cad2016珊瑚What’s the future of the world’s coral reefs?世界珊瑚礁的未来是什么? In February of 2020, scientists at University of Hawaii Manoa released a study addressing this very question. The models they developed forecasted a 70–90% worl…

EChart中使用地图方式总结(转载)

EChart中使用地图方式总结 2018年02月06日 22:18:57 来源:https://blog.csdn.net/shaxiaozilove/article/details/79274772最近在仿照EChart公交线路方向示例,开发表示排水网和污水网流向地图,同时地图上需要叠加排放口、污染源、污水处理厂等…

android mvp模式

越来越多人讨论mvp模式,mvp在android应用开发中获得更多的重视,这里说一下对MVP的简单了解。 什么是 MVP? MVP模式使逻辑从视图层分开,目的是我们在屏幕上怎么表现,和界面如何工作的所有事情就完全分开了。 View显示数据&…

Node.js REPL(交互式解释器)

2019独角兽企业重金招聘Python工程师标准>>> Node.js REPL(交互式解释器) Node.js REPL(Read Eval Print Loop:交互式解释器) 表示一个电脑的环境,类似 Window 系统的终端或 Unix/Linux shell,我们可以在终端中输入命令,并接收系统…

中国移动短信网关CMPP3.0 C#源代码:使用示例

中国移动短信网关CMPP3.0 C#源代码:使用示例 中国移动短信网关CMPP3.0 C#源代码使用,在上一篇文章中我介绍过cmpp3.0,这段时间因为也做关于移动短信网关的开发,在这里给大家一个演示如何使用cmpp3.0开发移动短信网关。Using Tiray.SMS... Ti…

用python进行营销分析_用python进行covid 19分析

用python进行营销分析Python is a highly powerful general purpose programming language which can be easily learned and provides data scientists a wide variety of tools and packages. Amid this pandemic period, I decided to do an analysis on this novel coronav…

名称

命名规则:Go中函数、变量、常量、类型、语句标签和包的名称都遵循一个规则,开头是一个字母或下划线,后面跟任意字符、数字和下划线,并区分大小写。例如:heapSort和HeapSort是不同名称。关键字:Go有25个关键…

Alpha冲刺第二天

Alpha第二天 1.团队成员 郑西坤 031602542 (队长) 陈俊杰 031602504陈顺兴 031602505张胜男 031602540廖钰萍 031602323雷光游 031602319苏芳锃 0316023302.项目燃尽图 3.项目进展 时间工作内容11月18日UI设计、初步架构搭建11月19日UI设计、服务器的进一…

Tiray.SMSTiray.SMSTiray.SMSTiray.SMSTiray.SMSTiray.SMS

这是2005年6月云南移动短信网关升级到3.0时写的,在SP那稳定运行了很长时间的。因为SP倒闭了,贴出来给有兴趣的朋友参考。优点:支持多线程、滑动窗口、异步发送、全事件模式、自动识别ASCII、GBK、UCS-2缺点:不支持长短信自动分页、…

水文分析提取河网_基于图的河网段地理信息分析排序算法

水文分析提取河网The topic of this article is the application of information technologies in environmental science, namely, in hydrology. Below is a description of the algorithm for ranking rivers and the plugin we implemented for the open-source geographic…

请不要更多的基本情节

“If I see one more basic blue bar plot…”“如果我再看到一个基本的蓝色条形图……” After completing the first module in my studies at Flatiron School NYC, I started playing with plot customizations and design using Seaborn and Matplotlib. Much like doodl…