intent跳转时添加动画效果实例

转自http://blog.csdn.net/yayun0516/article/details/45555945

系统默认的intent跳转效果非常生硬,丑陋,影响用户体验,怎么添加跳转动画呢?

首先新建两个动画文件:

zoomin.xml: 

[html] view plaincopy
  1. <?xml version="1.0" encoding="utf-8"?>   
  2. <set xmlns:android="http://schemas.android.com/apk/res/android"   
  3. android:interpolator="@android:anim/decelerate_interpolator">   
  4. <scale android:fromXScale="0.1" android:toXScale="1.0"   
  5. android:fromYScale="0.1" android:toYScale="1.0"   
  6. android:pivotX="50%p" android:pivotY="50%p"   
  7. android:duration="300" />   
  8. <!-- 这里为了看到动画演示效果,把动画持续时间设为3秒 -->   
  9. <alpha   
  10. android:fromAlpha="0.1"   
  11. android:toAlpha="1.0"   
  12. android:duration="300" />   
  13. </set>   


zoomout.xml

[html] view plaincopy
  1. <?xml version="1.0" encoding="utf-8"?>   
  2. <set xmlns:android="http://schemas.android.com/apk/res/android"   
  3. android:interpolator="@android:anim/decelerate_interpolator"   
  4. android:zAdjustment="top">   
  5. <scale android:fromXScale="1.0" android:toXScale=".5"   
  6. android:fromYScale="1.0" android:toYScale=".5"   
  7. android:pivotX="50%p" android:pivotY="50%p"   
  8. android:duration="300" />   
  9. <!-- 系统内置的动画持续时间   
  10. android:duration="@android:integer/config_mediumAnimTime"   
  11. -->   
  12. <alpha android:fromAlpha="1.0" android:toAlpha="0"   
  13. android:duration="300"/>   
  14. </set>   


然后只需在startActivity(intent)后面添加一句:

overridePendingTransition(R.anim.zoomin, R.anim.zoomout);

即可实现跳转动画效果,可以试试。


posted on 2015-06-14 10:19  moffis  阅读(640)  评论(0编辑  收藏  举报

导航