Activity的打开关闭或者说相互跳转之间可以设置动画的。默认的打开关闭直接消失或出现,比较不优美,但是有的手机Rom对这个默认做了修改,比如红米HM1,默认的就是新页面自右向左滑动出现,自左向右滑动消失。

设置动画有两种方法:

1。利用Activity的方法在代码中设置:

public void overridePendingTransition (int enterAnim, int exitAnim)
Call immediately after one of the flavors of startActivity(Intent) or finish() to specify an explicit transition animation to perform next.
enterAnimA resource ID of the animation resource to use for the incoming activity. Use 0 for no animation.
exitAnimA resource ID of the animation resource to use for the outgoing activity. Use 0 for no animation.
enterAnimA在此Actvity是将要出现的Activity时的进入动画。
exitAnimA在此Actvity是当前将要退出的Activity时的退出动画。

这个方法一定要在activity的start和finish之后立即调用。

 @Override
public void finish() {
super.finish();
if (isCloseAnim) {
this.overridePendingTransition(0, R.anim.activity_out_to_up);
} }

finish

Intent intent = new Intent(context, QuizActivity.class);
intent.putExtra(EXTRA_SCHEME_ID, schemeId);
context.startActivity(intent);
//设置切换动画,自下而上进入,自上而下退出
((Activity) context).overridePendingTransition(R.anim.activity_in_from_down, 0);

start

2。设置Activity的主题风格,在xml中实现:

在AndroidManifest里面,对于application和activity标签可以定义theme属性。如果对Application定义了某一个属性,那么会对所有的activity产生影响,当然可以在activity中覆盖它,为这个Activity添加自己的特定属性。

<application android:theme="@style/ThemeActivity"> 

然后在values/themes.xml中定义ThemeActivity这个主题

<style name="ThemeActivity" parent="Theme.AppCompat.Light.NoActionBar"> 
<item name="android:windowAnimationStyle">@style/AnimationActivity</item> 
<item name="android:windowNoTitle">true</item>
</style>
在values/styles.xml中定义AnimationActivity的style
<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>

至于anim中的动画在res/anim下用xml的set属性定义好就可以了。各个动画item的意义如下:

android:activityCloseEnterAnimation    When closing the current activity, this is the animation that is run on the next activity (which is entering the screen).

android:activityCloseExitAnimation    When closing the current activity, this is the animation that is run on the current activity (which is exiting the screen).

android:activityOpenEnterAnimation    When opening a new activity, this is the animation that is run on the next activity (which is entering the screen).

android:activityOpenExitAnimation    When opening a new activity, this is the animation that is run on the previous activity (which is exiting the screen).

Dialog和PopupWindow也可以设置动画。

比如在定义PopupWindow时指定动画:

setAnimationStyle(R.style.mypopwindow_anim_bottom_style);

activity的打开关闭动画的更多相关文章

  1. 设置Activity显示和关闭时的动画效果

    设置Activity显示和关闭时的动画效果 通过overridePendingTransition方法可以设置Activity显示和关闭的动画效果.首先需要在res/anim目录中建立相应的动画资源文 ...

  2. 两个activity的3D翻转动画.md

    一.业务需求 这里在公司项目设计时,用到了一个小的需求,就是点击一个按钮然后整个activity的页面进行3d翻转; 二.设计思路 由于是2个activity的之间的翻转动画,就意味着前90度是A页面 ...

  3. Activity Fragment转场动画

    Activity转场动画 先介绍个动画的好例子:https://github.com/lgvalle/Material-Animations Activity的转场动画是通过overridePendi ...

  4. activity fragment 转场动画

    http://www.cnblogs.com/avenwu/p/3372736.html v4 fragment fragmentTransaction.setCustomAnimations(R.a ...

  5. Android零基础入门第74节:Activity启动和关闭

    上一期我们学习了Activity的创建和配置,当时留了一个悬念,如何才能在默认启动的Activity中打开其他新建的Activity呢?那么本期一起来学习如何启动和关闭Activity. 一.概述 经 ...

  6. 通过暗码去打开/关闭usb debug开关

    通过暗码去打开/关闭usb debug开关 通过暗码去打开/关闭usb debug开关1. Description2. Analysis3. Solution4. Summary 1. Descrip ...

  7. CentOS7使用firewalld打开关闭防火墙与端口(转载)

    1.firewalld的基本使用 启动: systemctl start firewalld 查看状态: systemctl status firewalld 停止: systemctl disabl ...

  8. deepin gala窗口管理器关闭动画

    deepin中有两个管理器,一个基于metacity,另一个基于gala,可以用super+tab来进行切换.metacity是不带动画的,而 gala是带动画效果的.但这里有个问题,不知道有些同学上 ...

  9. Android activity界面跳转动画

    实现activity界面跳转动画 1.在startActivity方法之后加入: overridePendingTransition(R.anim.pull_in_right, R.anim.pull ...

随机推荐

  1. CSS制作出绚丽燃烧的火狐狸

    From here:http://www.webhek.com/firefox-animation/ ozilla在移动世界大会上宣布它的火狐操作系统(Firefox OS)的同时,也宣布了它的合作伙 ...

  2. 10-3[RF] feature selection

    main idea: 计算每一个feature的重要性,选取重要性前k的feature: 衡量一个feature重要的方式:如果一个feature重要,则在这个feature上加上noise,会对最后 ...

  3. php获取服务器地址

    if ( isset( $_SERVER['HTTP_X_FORWARDED_HOST'] ) ) { // Support ProxyPass        $t_hosts = explode( ...

  4. SVN—怎样安装SVNserver端软件

    一.怎样安装1.4.5版本号的SVNserver端软件:        a.下载1.4.5版本号的SVNserver端软件.下载地址:http://download.csdn.net/download ...

  5. andengine游戏引擎总结进阶篇2

    本篇包括瓦片地图,物理系统, 1瓦片地图 超级玛丽,冒险岛,魂斗罗等游戏主场景都有瓦片地图画成,它的作用可见一斑,它可以用tiled Qt软件画成,在辅助篇中讲讲解tiled Qt软件的使用 1)加载 ...

  6. Service的基本组成

    Service与Activity的最大区别就是一有界面,一个没有界面. 如果某些程序操作很消耗时间,那么可以将这些程序定义在Service之中,这样就可以完成程序的后台运行, 其实Service就是一 ...

  7. MessageQueue

    MessageQueue myQueue = new MessageQueue(".\\private$\\myQueue"); try { Message myMessage = ...

  8. 对浏览器css兼容性的学习理解及问题解决汇总

    一.从浏览器内核的角度 来看,浏览器兼容性问题可分为以下三类: 1. 渲染相关:和样式相关的问题,即体现在布局效果上的问题. 2. 脚本相关:和脚本相关的问题,包括JavaScript和DOM.BOM ...

  9. php获取post参数的几种方式

    php获取post参数的几种方式 1.$_POST['paramName'] 只能接收Content-Type: application/x-www-form-urlencoded提交的数据 2.fi ...

  10. MJExtension

    MJExtension 长话短说下面我们通过一个列子来看下怎么使用 1. 先把框架拉进去你的项目 2. 首先我这次用到的json最外层是一个字典,根据数据的模型我们可以把这个归类为字典中有数组,数组中 ...