转自http://blog.csdn.net/yayun0516/article/details/45555945
系统默认的intent跳转效果非常生硬,丑陋,影响用户体验,怎么添加跳转动画呢?
首先新建两个动画文件:
zoomin.xml:
-
<?xml version="1.0" encoding="utf-8"?>
-
<set xmlns:android="http://schemas.android.com/apk/res/android"
-
android:interpolator="@android:anim/decelerate_interpolator">
-
<scale android:fromXScale="0.1" android:toXScale="1.0"
-
android:fromYScale="0.1" android:toYScale="1.0"
-
android:pivotX="50%p" android:pivotY="50%p"
-
android:duration="300" />
-
-
<alpha
-
android:fromAlpha="0.1"
-
android:toAlpha="1.0"
-
android:duration="300" />
-
</set>
zoomout.xml
-
<?xml version="1.0" encoding="utf-8"?>
-
<set xmlns:android="http://schemas.android.com/apk/res/android"
-
android:interpolator="@android:anim/decelerate_interpolator"
-
android:zAdjustment="top">
-
<scale android:fromXScale="1.0" android:toXScale=".5"
-
android:fromYScale="1.0" android:toYScale=".5"
-
android:pivotX="50%p" android:pivotY="50%p"
-
android:duration="300" />
-
<!-- 系统内置的动画持续时间
-
android:duration="@android:integer/config_mediumAnimTime"
-
-->
-
<alpha android:fromAlpha="1.0" android:toAlpha="0"
-
android:duration="300"/>
-
</set>
然后只需在startActivity(intent)后面添加一句:
overridePendingTransition(R.anim.zoomin, R.anim.zoomout);
即可实现跳转动画效果,可以试试。