動畫效果 ObjectAnimator

學習了一下動畫效果的使用,作一下筆記數組

ImageView imageView = findViewById(R.id.imageView); ObjectAnimator.ofFloat(imageView,"translationY",0F,200F) .setDuration(1000).start();//translationX也能夠
 ObjectAnimator.ofFloat(imageView,"rotation",0F,360F) .setDuration(1000).start();//旋轉360度 //這裏是多個動畫同時實現 Y方向上的平移與自身的旋轉

 

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 animator1 = ObjectAnimator.ofFloat(imageView,"rotation",0,360F); ObjectAnimator animator2 = ObjectAnimator.ofFloat(imageView,"translationX",0,300F); ObjectAnimator animator3 = ObjectAnimator.ofFloat(imageView,"translationY",0,300F); AnimatorSet set=new AnimatorSet(); set.playTogether(animator1,animator2,animator3);//同時
set.setDuration(1000); set.start();

 

ObjectAnimator animator1 = ObjectAnimator.ofFloat(imageView,"rotation",0,360F); ObjectAnimator animator2 = ObjectAnimator.ofFloat(imageView,"translationX",0,300F); ObjectAnimator animator3 = ObjectAnimator.ofFloat(imageView,"translationY",0,300F); AnimatorSet set = new AnimatorSet(); set.playSequentially(animator1,animator2,animator3);//按照順序開始動畫
set.setDuration(1000); set.start();

 

經過with,after,before來定義多個動畫以前的前後順序ide

set.play(animator2).with(animator3); set.play(animator1).after(animator2);

 

ObjectAnimator animator = ObjectAnimator.ofFloat(view,"alpha",0F,1F);//設置透明度 animator.setDuration(1000);// 1000ms animator.addListener(new AnimatorListenerAdapter() {//設置監聽器
  //這裏只重寫了 end的監聽,也能夠重寫 start等監聽 @Override
public void onAnimationEnd(Animator animation) { super.onAnimationEnd(animation);//end時 toast Toast.makeText(MainActivity.this,"anim end",Toast.LENGTH_SHORT).show(); } }); animator.start();
相關文章
相關標籤/搜索