开源地址: 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的更多相关文章

  1. [转]Android开源项目第二篇——工具库篇

    本文为那些不错的Android开源项目第二篇--开发工具库篇,主要介绍常用的开发库,包括依赖注入框架.图片缓存.网络相关.数据库ORM建模.Android公共库.Android 高版本向低版本兼容.多 ...

  2. Android开源项目分类汇总

    目前包括: Android开源项目第一篇——个性化控件(View)篇   包括ListView.ActionBar.Menu.ViewPager.Gallery.GridView.ImageView. ...

  3. 100个Github上Android开源库

    项目名称 项目简介 1. react-native 这个是 Facebook 在 React.js Conf 2015 大会上推出的基于 JavaScript 的开源框架 React Native, ...

  4. GitHub上史上最全的Android开源项目分类汇总 (转)

    GitHub上史上最全的Android开源项目分类汇总 标签: github android 开源 | 发表时间:2014-11-23 23:00 | 作者:u013149325 分享到: 出处:ht ...

  5. 直接拿来用!最火的Android开源项目(二)(转)

    GitHub上的开源项目不胜枚举,通过这些项目,也能让开发者在应用开发过程中事半功倍,作为开发者的你,在用这些开源项目吗?今天我们将介绍另外20个在GitHub上备受欢迎的Android开源项目,你准 ...

  6. GitHub 优秀的 Android 开源项目(转)

    今天查找资源时看到的一篇文章,总结了很多实用资源,十分感谢原作者分享. 转自:http://blog.csdn.net/shulianghan/article/details/18046021 主要介 ...

  7. GitHub上排名前100的Android开源库介绍(来自github)

    本项目主要对目前 GitHub 上排名前 100 的 Android 开源库进行简单的介绍,至于排名完全是根据 GitHub 搜索 Java 语言选择 (Best Match) 得到的结果,然后过滤了 ...

  8. 直接拿来用!最火的Android开源项目

    GitHub在中国的火爆程度无需多言,越来越多的开源项目迁移到GitHub平台上.更何况,基于不要重复造轮子的原则,了解当下比较流行的Android与iOS开源项目很是必要.利用这些项目,有时能够让你 ...

  9. GitHub Top 100的Android开源库

    摘要: 本项目主要对目前 GitHub 上排名前 100 的 Android 开源库进行简单的介绍, 至于排名完全是根据GitHub搜索Java语言选择「Best M... 本项目主要对目前 GitH ...

随机推荐

  1. Fedora 28 设置yum代理

    编辑  vi /etc/dnf/dnf.conf 文件 添加一行代理设置:proxy=http://****:****

  2. git push --set-upstream origin

    设置本地分支追踪远程分支 之后就可以直接使用git push提交代码

  3. VUE购物车示例

    代码下载地址:https://github.com/MengFangui/VueShoppingCart 1.index.html <!DOCTYPE html> <html lan ...

  4. name_search方法的使用

    转自:http://blog.csdn.net/littlebo01/article/details/22075573 在many2one类型中,页面下拉时会首先触发name_search方法,参数这 ...

  5. IOS Exception 1(libc++abi.dylib: terminating with uncaught exception of type NSException)

    2014-08-05 22:18:46.455 SwiftUI[1329:40871] -[_TtC7SwiftUI14MViewControler clickMe]: unrecognized se ...

  6. 【VBA编程】07.循环结构语句

    [FOR...NEXT语句] For counter = start To End [Step step] [statements] [Exit For] [statements] Next [cou ...

  7. swift向方法传数组参数的语法

    总是记不住向方法中传数组参数的语法,所以记录一下. func calculateStatistics(scores:[Int]) -> (min:Int,max:Int,sum:Int) { v ...

  8. SSL and SSL Certificates Explained

    Secure Sockets Layer (SSL) and Transport Layer security (TLS ) are protocols that provide secure com ...

  9. SSE,MSE,RMSE,R-square 指标讲解

    SSE(和方差.误差平方和):The sum of squares due to error MSE(均方差.方差):Mean squared errorRMSE(均方根.标准差):Root mean ...

  10. C语言 fork

    /* *@author cody *@date 2014-08-12 *@description */ /* #include <sys/types.h> #include <uni ...