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源码分析总结单例模式的几种实现方式
- 【原创】关于前端动画的几种实现方式和总结
- Android主界面Tab的几种实现方式;7.18日学习总结
- Android中帧动画在Activity启动时自动运行的几种方式
- Android中帧动画在Activity启动时自动运行的几种方式
- Android中帧动画在Activity启动时自动运行的几种方式
- Android中帧动画在Activity启动时自动运行的几种方式
- URL重写的几种实现方式的总结
- Android 编程下帧动画在 Activity 启动时自动运行的几种方式
- Android中帧动画在Activity启动时自动运行的几种方式
- Android中帧动画在Activity启动时自动运行的几种方式
- Android点击Button实现功能的几种方法总结
- URL重写的几种实现方式的总结
- Android 定时器实现的几种方式和removeCallbacks失效问题详解
- android中动画实现的两种方式
- android 获取手机自定位的几种实现方式
- URL重写的几种实现方式的总结
- android 定时任务的几种实现方式
- Android共享文件的几种方式(我这里只总结到了SQLiteDatabase、SharedPreferences、ContentProvider)
- android中Button监听器的几种实现方式