您的位置:首页 > 移动开发 > Android开发

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

2017-09-07 09:38 369 查看

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

<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
>

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

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

...

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

</animation-list>

<ImageView
android:id="@+id/img_anim"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/animation_list_refresh"
/>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  android 动画