【Android】PropertyAnimation属性动画

ObjectAnimator常用属性:

translationX、translationY ;rotation、rotationX、rotationY ;scaleX、scaleY ; X、Y; alpha;

常用方法、类:

ValueAnimator、ObjectAnimator、AnimatorUpdateListener、AnimatorListenerAdapter、PropertyValuesHolder、AnimatorSet、TypeEvalueators、Interpolators
差值器Interpolato


动画的使用

public void move(View view){

//        TranslateAnimation animation = new TranslateAnimation(0,200, 0,0);
//        animation.setDuration(1000);
//        animation.setFillAfter(true);
//
//        imageView.startAnimation(animation);

//          <一 :ObjectAnimator>
//        ObjectAnimator.ofFloat(imageView, "rotation", 0, 360F).setDuration(1000).start();
//        ObjectAnimator.ofFloat(imageView, "translationX", 0, 200F).setDuration(1000).start();
//        ObjectAnimator.ofFloat(imageView, "translationY", 0, 200F).setDuration(1000).start();
//
//          <二:PropertyValuesHolder> 
//        PropertyValuesHolder p1 = PropertyValuesHolder.ofFloat("rotation",0,360F);
//        PropertyValuesHolder p2 = PropertyValuesHolder.ofFloat("translationX",0,200F);
//        PropertyValuesHolder p3 = PropertyValuesHolder.ofFloat("translationY",0,200F);
//        ObjectAnimator.ofPropertyValuesHolder(imageView, p1, p2, p3).setDuration(1000).start();

            <三:ObjectAnimator--AnimatorSet可以修改动画顺序>
          ObjectAnimator animation1 = ObjectAnimator.ofFloat( imageView, "rotation",0,360F);
          ObjectAnimator animation2 = ObjectAnimator.ofFloat( imageView, "translationX",0,200F);
          ObjectAnimator animation3 = ObjectAnimator.ofFloat( imageView, "translationY",0,200F);
          AnimatorSet set = new AnimatorSet();
//        set.playTogether(animation1, animation2, animation3);
//        set.playSequentially(animation1,animation3,animation2);
          set.play(animation1).with(animation2);
          set.play(animation3).before(animation2);
          set.setDuration(1000);
          set.start();
     }

监听动画

anim.addListener( new AnimatorListenerAdapter() {

                 @Override
                    //不用完全实现Listener方法
                 public void onAnimationEnd(Animator animation) {
                      super.onAnimationEnd(animation);
                     Toast. makeText(ListenAnimActivity. this, "Animation end" , Toast.LENGTH_LONG ).show();

                }
           });


//anim.addListener(new AnimatorListener() {
//
//              @Override
//              public void onAnimationStart(Animator animation) {
//              }
//
//              @Override
//              public void onAnimationRepeat(Animator animation) {
//              }
//
//              @Override
//              public void onAnimationEnd(Animator animation) {
//                   Toast.makeText(ListenAnimActivity.this, "Animation end", Toast.LENGTH_LONG).show();
//
//              }
//
//              @Override
//              public void onAnimationCancel(Animator animation) {
//              }
//         });

ValueAnimator

//             final Button button = (Button) view;
//               产生0~100随机数
            // ValueAnimator animator = ValueAnimator.ofInt(0, 100);
            // animator.setDuration(5000);
            // animator.addUpdateListener(new AnimatorUpdateListener() {
            //
            // @Override
            // public void onAnimationUpdate(ValueAnimator animation) {
            // Integer value = (Integer) animation.getAnimatedValue();
            // button.setText("" + value);
            // }
            // });
            // animator.start();

Thanks慕课网

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值