标签:
今天沈阳斌子在做APP时,客户的需求变更是在原有的程序上加入跳转页面的动画切换,类似IPhone的左出右进的方式,返回时是相反的效果。我知道用两种方式可以实现这样的效果,一种就是通过在startActivity后执行overridePendingTransition方法进行动画的切换,同样finish也是一样的。下面就是我封装好的方法:
/** * * @Description : 跳转页面的左出和右进的效果 * @Method_Name : startActivityAnim * @param activity * @return : void * @Creation Date : 2015-1-5 上午10:20:37 * @version : v1.00 * @Author : JiaBin * @Update Date : * @Update Author : JiaBin */ public static void startActivityAnim(Activity activity, Class<?> cla) { Intent intent = new Intent(); intent.setClass(activity, cla); activity.startActivity(intent); // 设置切换动画,从右边进入,左边退出 activity.overridePendingTransition(R.anim.in_from_right, R.anim.out_to_left); }
1.首先在style.xml中声明如下代码:
<style name="AnimationActivity" parent="@android:style/Animation.Activity"> <item name="android:activityOpenEnterAnimation">@anim/push_left_in</item> <item name="android:activityOpenExitAnimation">@anim/push_left_out</item> <item name="android:activityCloseEnterAnimation">@anim/push_right_in</item> <item name="android:activityCloseExitAnimation">@anim/push_right_out</item> </style>2.在style.xml中声明如下代码:
<style name="themeSetting"> <item name="android:windowAnimationStyle">@style/AnimationActivity</item> </style>
<activity android:name="com.nearprint.MainNewActivity" android:label="@string/app_name" android:screenOrientation="portrait" android:theme="@style/themeSetting<span style="font-family: Arial, Helvetica, sans-serif;">" ></span>以上三步就可以实现访问跳转Activity的动画的切换问题,下面贴出相应的动画文件。
in_from_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:duration="500" android:fromXDelta="100%p" android:toXDelta="0%p" /> </set>
<?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:duration="500" android:fromXDelta="0%p" android:toXDelta="-100%p" /> </set>
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android"> <translate android:fromXDelta="100%p" android:toXDelta="0" android:duration="500" /> <alpha android:fromAlpha="0.1" android:toAlpha="1.0" android:duration="500" /> </set>
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android"> <translate android:fromXDelta="0" android:toXDelta="-100%p" android:duration="500" /> <alpha android:fromAlpha="1.0" android:toAlpha="0.1" android:duration="500" /> </set>
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android"> <translate android:fromXDelta="-100%" android:toXDelta="0" android:duration="500" /> <alpha android:fromAlpha="0.1" android:toAlpha="1.0" android:duration="500" /> </set>
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android"> <translate android:fromXDelta="0" android:toXDelta="100%" android:duration="500" /> <alpha android:fromAlpha="1.0" android:toAlpha="0.1" android:duration="500" /> </set>
Android 关于Activity的跳转和finish时切换页面动画实现
标签:
原文地址:http://blog.csdn.net/sy_bz/article/details/42422731