Android动画的几种实现方式总结

1、AnimatorSet

AnimatorSet set = new AnimatorSet();
set.playTogether(
        ObjectAnimator.ofFloat( imageViewOne, "scaleX" , 1, 1.3f, 1 ),
        ObjectAnimator. ofFloat(imageViewOne, "scaleY", 1 , 1.3f, 1),
        ObjectAnimator. ofFloat(imageViewTwo, "translationX", 0 , 60, 30),
        ObjectAnimator. ofFloat(imageViewTwo, "translationY", 0 , 60, 30),
        ObjectAnimator. ofFloat(imageViewThree, "alpha", 0 , 1) ,
        ObjectAnimator. ofFloat(imageViewFour, "rotation", 0 , 180)
);
//减速器
 set.setInterpolator(new AccelerateDecelerateInterpolator()) ;
//加速器
set.setInterpolator(new AccelerateInterpolator()) ;
//延迟
set.setStartDelay(1000) ;
//监听器
set.addListener( this);
set.setDuration(6000).start() ;

或者:

<set xmlns:android="http://schemas.android.com/apk/res/android">
//改变透明度:
<alpha
        android:duration="3000"
        android:fromAlpha="0"
        android:repeatCount="3"
        android:repeatMode="restart"
        android:toAlpha="1" >
    </alpha>
//旋转:
    <rotate
        android:duration="3000"
        android:fromDegrees="0"
        android:pivotX="50%"
        android:pivotY="50%"
        android:toDegrees="-360" >
    </rotate>
//缩放:
    <scale
        android:duration="3000"
        android:fromXScale="0"
        android:fromYScale="0"
        android:pivotX="50%"
        android:pivotY="50%"
        android:toXScale="2"
        android:toYScale="2" >
    </scale>
//平移:
    <translate
        android:duration="1000"
        android:fillAfter="true"
        android:fromXDelta="0"
        android:toXDelta="-300" >
</translate>
</set>
//Java代码:
Animation animation=
            AnimationUtils.loadAnimation(context,相应的xml文件);
imageVie.startAnimation(animation);

2、ViewCompat

  ViewCompat.animate(view)
                    .scaleX(0.f)
                    .scaleY(0.f)
                    .rotationBy(360)
                    .translationX(60f)
                    .translationY(60f)
                    .setStartDelay(500)
                    .setDuration(1000)
                    .withEndAction(new Runnable() {
                        @Override
                        public void run() {

                        }
                    });

3、AnimationDrawable

"http://schemas.android.com/apk/res/android"
    >

    "@drawable/icon_1"
          android:duration="80"/>

    "@drawable/icon_2"
          android:duration="80"/>

    ...

    "@drawable/icon_8"
          android:duration="80"/>



    "@+id/img_anim"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/animation_list_refresh"
        />

你可能感兴趣的:(Android)