• 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);


  • 相关阅读:
    两数之和等于目标值
    Atitit.软件仪表盘(0)--软件的子系统体系说明
    获取 exception 对象的字符串形式(接口服务返回给调用者)
    SELECT LAST_INSERT_ID() 的使用和注意事项
    @RequestParam 注解的使用
    Eclipse中修改SVN用户名和密码方法
    淘淘商城上传图片按钮不显示的问题
    spring集成webSocket实现服务端向前端推送消息
    Mybatis中jdbcType和javaType对应关系
    MySQL数据库中tinyint字段值为1,读取出来为true的问题
  • 原文地址:https://www.cnblogs.com/tlnshuju/p/7262170.html
Copyright © 2020-2023  润新知