几个activity跳转特效的实现

放大淡出效果:

my_scale_action.xml

<?xml version="1.0" encoding="utf-8" ?> 
- <!--  android:duration="@android:integer/config_mediumAnimTime" 
  --> 
- <set xmlns:android="http://schemas.android.com/apk/res/android">
  <scale android:interpolator="@android:anim/accelerate_decelerate_interpolator" android:fromXScale="0.0" android:toXScale="1.4" android:fromYScale="0.0" android:toYScale="1.4" android:pivotX="50%" android:pivotY="50%" android:fillAfter="false" android:duration="2000" /> 
  </set>

 my_alpha_action.xml

<?xml version="1.0" encoding="utf-8" ?> 
- <!--  android:duration="@android:integer/config_mediumAnimTime" 
  --> 
- <set xmlns:android="http://schemas.android.com/apk/res/android">
  <alpha android:fromAlpha="1.0" android:toAlpha="0" android:duration="2000" /> 
  </set>

左上角展开淡出效果:

scale_translate.xml

<?xml version="1.0" encoding="utf-8" ?> 
- <!--  android:duration="@android:integer/config_mediumAnimTime" 
  --> 
- <set xmlns:android="http://schemas.android.com/apk/res/android" android:shareInterpolator="false">
  <scale android:interpolator="@android:res/anim/accelerate_decelerate_interpolator" android:fromXScale="0.0" android:toXScale="1.0" android:fromYScale="0.0" android:toYScale="1.0" android:pivotX="0" android:pivotY="0" android:duration="2000" android:repeatCount="0" android:startOffset="0" /> 
  <translate android:fromXDelta="0" android:toXDelta="0" android:fromYDelta="0" android:toYDelta="0" android:duration="2000" /> 
  </set>

my_alpha_action.xml

<?xml version="1.0" encoding="utf-8" ?> 
- <!--  android:duration="@android:integer/config_mediumAnimTime" 
  --> 
- <set xmlns:android="http://schemas.android.com/apk/res/android">
  <alpha android:fromAlpha="1.0" android:toAlpha="0" android:duration="2000" /> 
  </set>

转动淡出效果:

scale_rotate.xml

<?xml version="1.0" encoding="utf-8" ?> 
- <!--  android:duration="@android:integer/config_mediumAnimTime" 
  --> 
- <set xmlns:android="http://schemas.android.com/apk/res/android" android:shareInterpolator="false">
  <scale android:interpolator="@android:res/anim/accelerate_decelerate_interpolator" android:fromXScale="0.0" android:toXScale="1.0" android:fromYScale="0.0" android:toYScale="1.0" android:pivotX="50%" android:pivotY="50%" android:duration="2000" android:repeatCount="0" android:startOffset="20" /> 
  <rotate android:interpolator="@android:anim/accelerate_decelerate_interpolator" android:fromDegrees="0" android:toDegrees="+355" android:pivotX="50%" android:pivotY="50%" android:duration="2000" /> 
  </set>

 

my_alpha_action.xml

<?xml version="1.0" encoding="utf-8" ?> 
- <!--  android:duration="@android:integer/config_mediumAnimTime" 
  --> 
- <set xmlns:android="http://schemas.android.com/apk/res/android">
  <alpha android:fromAlpha="1.0" android:toAlpha="0" android:duration="2000" /> 
  </set>

左右交错效果:

slide_left.xml

<?xml version="1.0" encoding="utf-8" ?> 
- <set xmlns:android="http://schemas.android.com/apk/res/android" android:interpolator="@android:anim/accelerate_interpolator">
  <translate android:fromXDelta="100%p" android:toXDelta="0" android:duration="2000" /> 
  </set>

slide_right.xml

<?xml version="1.0" encoding="utf-8" ?> 
- <set xmlns:android="http://schemas.android.com/apk/res/android" android:interpolator="@android:anim/accelerate_interpolator">
  <translate android:fromXDelta="-100%p" android:toXDelta="0" android:duration="2000" /> 
  </set>

 java代码中使用函数overridePendingTransition(),此函数有两个参数,第一个是前activity的退出,第二个是后activity的进入。在res下创建一个新文件夹anim,将实现效果的xml文件放入,调用即可实现。

如:overridePendingTransition(R.anim.my_scale_action,R.anim.my_alpha_action);

注意:overridePendingTransition()函数的使用一定要在startactivity()或finish()之后。

相关推荐