在Android中,两个activiyt的切换总是自左向右抽动的效果

在Activity中提供了overridePendingTransition函数,用在startActivity(Intent) 或 finish之后,


overridePendingTransition有两个参数,都是int类型的,意味着这里要传入一个资源,

在sdk中是这样定义的、


enterAnim A resource ID of the animation resource to use for the incoming activity. Use 0 for no animation.
exitAnim A resource ID of the animation resource to use for the outgoing activity. Use 0 for no animation.


一个是进入的动画,一个是退出的动画,如果连个值都设置成0,则表示不添加动画

即:overridePendingTransition(0, 0);

例如 在startActivity开启一个intent之后,添加如下代码

overridePendingTransition(Android.R.anim.fade_in, android.R.anim.fade_out);
这样在启动下一个窗口的时候出现淡入淡出的效果


//实现从左向右滑动效果
overridePendingTransition(Android.R.anim.slide_in_left,
Android.R.anim.slide_out_right);

另外,还可以通过在资源文件夹中anim中添加自定义的配置文件,来实现自定义过度动画

例如在程序中添加这样的 效果来实现和iphone一样的效果

overridePendingTransition(R.anim.zoomin, R.anim.zoomout);
自定义的zoomin.xml文件,该文件设置了新的activity进入时的效果
<?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="2.0" android:toXScale="1.0"
Android:fromYScale="2.0" android:toYScale="1.0"
Android:pivotX="50%p" android:pivotY="50%p"
Android:duration="@android:integer/config_mediumAnimTime" />
</set>


自定义的zoomout.xml文件,该文件设置了原来的activity退出是的效果
<?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="2.0" android:toXScale="0.5"
Android:fromYScale="2.0" android:toYScale="0.5"
Android:pivotX="50%p" android:pivotY="50%p"
Android:duration="@android:integer/config_mediumAnimTime" />
<alpha
Android:fromAlpha="1.0"
Android:toAlpha="0"
Android:duration="@android:integer/config_mediumAnimTime" />
</set>

最后在友情提示一下给没有仔细看的同学,此方法会在startActivity和finish之后立即调用。

意思是说,你要在A start B的时候调用一次,还要在B finish的时候调用一次,才有连贯的动画!记得有两次喔!

更多相关文章

  1. [android] toast解析
  2. 动手学Android之九——列表没那么简单
  3. Android(安卓)Studio编译提示警告xxx已过时
  4. Android(安卓)快速开发之快速实现“我”界面
  5. Android(安卓)Animation学习笔记
  6. 使用ScrollView实现滚动效果
  7. 历史最牛 多页切换TabHost,给大家参考。
  8. Android里五种 Toast方式
  9. Android(安卓)加载等待控件 ZFProgressHUD

随机推荐

  1. Android NDK: Host 'awk' tool is outdat
  2. 关于Android连接远程数据库(mysql、oracle
  3. Android(安卓)5.0 documentation CHM 版
  4. 整理分享ImageView属性大全
  5. android 休眠唤醒机制分析(一)
  6. 如何在横屏控制软键盘显示一部分
  7. android 一 android 的生命周期
  8. Android configChanges用法
  9. android中ImageView属性及其详解
  10. Android 搜索框:SearchView 的属性和用法