Android activity界面跳转动画

实现activity界面跳转动画

1.在startActivity方法之后加入:

overridePendingTransition(R.anim.pull_in_right, R.anim.pull_out_left)这个方法。

如果R.anim 不存在的话就在res下新建一个anim文件夹

R.anim.pull_in_right//同样在anim文件下面新建一个pull_in_left.xml文件

  <scale xmlns:android="http://schemas.android.com/apk/res/android"
       android:duration="@integer/animTime"
       android:fromXScale="0%"
       android:fromYScale="100%"
       android:pivotX="100%"
       android:pivotY="100%"
       android:toXScale="100%"
       android:toYScale="100%"/>

R.anim.pull_out_left

<set xmlns:android="http://schemas.android.com/apk/res/android">
       <scale
            android:duration="@integer/animTime"
            android:fromXScale="100%"
            android:fromYScale="100%"
            android:pivotX="0%"
            android:pivotY="0%"
            android:toXScale="0%"
            android:toYScale="100%"/>
      <alpha
            android:duration="@integer/animTime"
            android:fromAlpha="1"
            android:toAlpha="0.2"
            >
      </alpha>
      </set>

2.如果要返回动画的的话就重写finish在super.finish()之后加入:

overridePendingTransition(R.anim.pull_in_left, R.anim.pull_out_right);

R.anim.pull_in_left

      <scale xmlns:android="http://schemas.android.com/apk/res/android"
       android:duration="@integer/animTime"
       android:fromXScale="0%"
       android:fromYScale="100%"
       android:pivotX="0%"
       android:pivotY="0%"
       android:toXScale="100%"
       android:toYScale="100%"/>

R.anim.pull_out_right

  <set xmlns:android="http://schemas.android.com/apk/res/android">
      <scale
            android:duration="@integer/animTime"
            android:fromXScale="100%"
            android:fromYScale="100%"
            android:pivotX="100%"
            android:pivotY="100%"
            android:toXScale="0%"
            android:toYScale="100%"/>
     <alpha
            android:duration="@integer/animTime"
            android:fromAlpha="1"
            android:toAlpha="0.2"
            >
     </alpha>
     </set>

上一篇:Android Activity切换(跳转)时出现黑屏的解决方法


下一篇:Structs 2