标签:android style blog http color io ar java for
开源地址: 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);
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()); } });
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使其恢复原样//转换动画的轨迹
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);
animate(target).setDuration(2000); animate(animatingButton).alpha(0); animate(animatingButton).x(xValue).y(yValue); animate(animatingButton).rotationYBy(720);
标签:android style blog http color io ar java for
原文地址:http://blog.csdn.net/qq285016127/article/details/40372635