Android开源-NineOldAndroids
开源地址: https://github.com/JakeWharton/NineOldAndroids
简单介绍:NineOldAndroids是一款支持在低版本号开发的Android动画的框架 包含了一系列如ViewAnimator,ObjectAnimator,
ViewPropertyAnimator等API,攻克了Tween动画中移动过程仅仅显示移动效果,而不是真正组件的问题.
1)创建ObjectAnimator
ObjectAnimator anim1=ObjectAnimator.ofFloat(balls.get(0),"y",0f,getHeight()-balls.get(0).getHeight()).setDuration(500);
调用開始 animation.start();
克隆 ObjectAnimator anim2=anim1.clone();
2)定义动画组
ObjectAnimator animDown=ObjectAnimator.ofFloat(balls.get(2), "y",0f,getHeight()-balls.get(2).getHeight()).setDuration(500);
ObjectAnimator animUp=ObjectAnimator.ofFloat(balls.get(2), "y",getHeight()-balls.get(2).getHeight(),0f).setDuration(500);
AnimatorSet s1=new AnimatorSet();
使动画具有连贯性 s1.playSequentially(animDown,animUp);
使动画时间開始一致 animation.playTogether(anim1,anim2,s1);
3)值动画(AnimatorInflater布局载入器)
ValueAnimator alphaAnimator=(ValueAnimator) AnimatorInflater.loadAnimator(AnimationLoading.this,R.anim.animator);
alphaAnimator.setTarget(balls.get(1));
alphaAnimator.addUpdateListener(new AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
balls.get(1).setAlpha((Float) animation.getAnimatedValue());
}
});
4)动画集
AnimatorSet s1=(AnimatorSet) AnimatorInflater.loadAnimator(AnimationLoading.this,R.anim.animator_set);
s1.setTarget(balls.get(2));
对象动画(移动/颜色改变)
ObjectAnimator s2=(ObjectAnimator) AnimatorInflater.loadAnimator(AnimationLoading.this, R.anim.color_animator);
s2.setTarget(balls.get(3));
定义动画顺序
((AnimatorSet)animation).play(animX).before(animY);//animX在animY前面
((AnimatorSet)animation).play(animX).with(animY);//animX与animY同步运行
//圆弧加速器
new CycleInterpolator(2.0f)
//定义各种属性>汇总
PropertyValuesHolder animY=PropertyValuesHolder.ofFloat("y",balls.get(1).getY(),getHeight()-100);
PropertyValuesHolder alpha=PropertyValuesHolder.ofFloat("alpha",1.0f,.5f);
ObjectAnimator pvhAlpha=ObjectAnimator.ofPropertyValuesHolder(balls.get(1), animY,alpha).setDuration(1000);
//设置放大动画
PropertyValuesHolder widthHolder=PropertyValuesHolder.ofFloat("width",ball.getWidth(),ball.getWidth()*2);
PropertyValuesHolder heightHolder=PropertyValuesHolder.ofFloat("height",ball.getHeight(),ball.getHeight()*2);
PropertyValuesHolder xPt=PropertyValuesHolder.ofFloat("x",ball.getX(),ball.getX()-BALL_SIZE/2f);
PropertyValuesHolder yPt=PropertyValuesHolder.ofFloat("y",ball.getY(),ball.getY()-BALL_SIZE/2f);
ObjectAnimator sumAnimator=ObjectAnimator.ofPropertyValuesHolder(ball,widthHolder,heightHolder,xPt,yPt).setDuration(750);
sumAnimator.setRepeatMode(ValueAnimator.REVERSE);
sumAnimator.setRepeatCount(1);//设置repeatCount=1使其恢复原样
//转换动画的轨迹
bounceAnim.reverse();
***************************************ObjectAnimator组件应用*************************************
位移:移动的单位为像素,能够指定一系列的位置
ObjectAnimator.ofFloat(target,"translationX",0,50).setDuration(duration).start();
ObjectAnimator.ofFloat(target,"translationY",0,50,-50,0).setDuration(duration).start();
缩放:1.0f代表为原来长/宽度的1倍,同理其它.全部的倍数都是因最早设定的宽度成倍
ObjectAnimator.ofFloat(target,"scaleX",1,2,1).setDuration(duration).start();
ObjectAnimator.ofFloat(target,"scaleY",1,2).setDuration(duration).start();
透明度:1.0f表示不透明 0表示全透明
ObjectAnimator.ofFloat(target,"alpha",1,0,1).setDuration(duration).start();
旋转:
ObjectAnimator.ofFloat(target,"rotationX",0,180,0).setDuration(duration).start();
ObjectAnimator.ofFloat(target,"rotationY",0,360).setDuration(duration).start();
ObjectAnimator.ofFloat(target,"rotation",0,180,0).setDuration(duration).start();
设置变换中心;当然,多个动画能够组合变换
ViewHelper.setPivotX(target,target.getWidth()/2);
ViewHelper.setPivotY(target,target.getHeight()/2);
***************************************ViewPropertyAnimator组件应用*************************************
animate(target).setDuration(2000);
animate(animatingButton).alpha(0);
animate(animatingButton).x(xValue).y(yValue);
animate(animatingButton).rotationYBy(720);
Android开源-NineOldAndroids的更多相关文章
- [转]Android开源项目第二篇——工具库篇
本文为那些不错的Android开源项目第二篇--开发工具库篇,主要介绍常用的开发库,包括依赖注入框架.图片缓存.网络相关.数据库ORM建模.Android公共库.Android 高版本向低版本兼容.多 ...
- Android开源项目分类汇总
目前包括: Android开源项目第一篇——个性化控件(View)篇 包括ListView.ActionBar.Menu.ViewPager.Gallery.GridView.ImageView. ...
- 100个Github上Android开源库
项目名称 项目简介 1. react-native 这个是 Facebook 在 React.js Conf 2015 大会上推出的基于 JavaScript 的开源框架 React Native, ...
- GitHub上史上最全的Android开源项目分类汇总 (转)
GitHub上史上最全的Android开源项目分类汇总 标签: github android 开源 | 发表时间:2014-11-23 23:00 | 作者:u013149325 分享到: 出处:ht ...
- 直接拿来用!最火的Android开源项目(二)(转)
GitHub上的开源项目不胜枚举,通过这些项目,也能让开发者在应用开发过程中事半功倍,作为开发者的你,在用这些开源项目吗?今天我们将介绍另外20个在GitHub上备受欢迎的Android开源项目,你准 ...
- GitHub 优秀的 Android 开源项目(转)
今天查找资源时看到的一篇文章,总结了很多实用资源,十分感谢原作者分享. 转自:http://blog.csdn.net/shulianghan/article/details/18046021 主要介 ...
- GitHub上排名前100的Android开源库介绍(来自github)
本项目主要对目前 GitHub 上排名前 100 的 Android 开源库进行简单的介绍,至于排名完全是根据 GitHub 搜索 Java 语言选择 (Best Match) 得到的结果,然后过滤了 ...
- 直接拿来用!最火的Android开源项目
GitHub在中国的火爆程度无需多言,越来越多的开源项目迁移到GitHub平台上.更何况,基于不要重复造轮子的原则,了解当下比较流行的Android与iOS开源项目很是必要.利用这些项目,有时能够让你 ...
- GitHub Top 100的Android开源库
摘要: 本项目主要对目前 GitHub 上排名前 100 的 Android 开源库进行简单的介绍, 至于排名完全是根据GitHub搜索Java语言选择「Best M... 本项目主要对目前 GitH ...
随机推荐
- 详解php的魔术方法__get()和__set()
先看看php官方文档的解释:__set() is run when writing data to inaccessible properties.__get() is utilized for re ...
- 说说C#之父——安德斯·海尔斯伯格
安德斯·海尔斯伯格(Anders Hejlsberg,1960.12~),丹麦人,Turbo Pascal编译器的主要作者,Delphi和.NET之父! 看到照片的那一刹那儿,我就觉得帅爆了,53岁的 ...
- LeetCode-NQueensII
经典的N皇后问题, 这里学到了一个非常牛的新方法(http://www.matrix67.com/blog/archives/266),用位运算来求解N皇后问题: 思路其实也很容易懂,一点都不复杂, ...
- JMeter 十二:命令行执行
参考文档:http://jmeter.apache.org/usermanual/get-started.html#non_gui 真正开始跑压力测试时,我们就不能使用GUI模式了.这时候需要采用命令 ...
- java提高篇-----理解java的三大特性之封装
在<Think in java>中有这样一句话:复用代码是Java众多引人注目的功能之一.但要想成为极具革命性的语言,仅仅能够复制代码并对加以改变是不够的,它还必须能够做更多的事情.在这句 ...
- python 字典的KeyError处理方法
先看一段代码: user = dict(name="brainliao", age=32) print(user["sex"]) 运行结果如下: user这个字 ...
- 为LoadRunner写一个lr_save_float函数
LoadRunner中有lr_save_int() 和lr_save_string() 函数,但是没有保存浮点数到变量的lr_save_float函数.<lr_save_float() func ...
- js math 对数和指数处理 expm1 log1p
1.Math.expm1() Math.expm1(x)返回 ex - 1,即Math.exp(x) - 1. Math.expm1(-1) // -0.6321205588285577 Math.e ...
- oracle 事务多表查询以及额外的用处
/* 以下代码是对emp表进行显示宽度设置*/ col empno for 9999;col ename for a10;col job for a10;col mgr for 9999;col hi ...
- 将项目从tomcat 迁移到JBoss5.0
http://java-boy.iteye.com/blog/531411从Tomcat升级到JBoss5.1真是一个痛苦的过程,可能遇到很多问题.以下是我碰到的问题,及解决方法. 一.Hiberna ...