activity的打开关闭动画
Activity的打开关闭或者说相互跳转之间可以设置动画的。默认的打开关闭直接消失或出现,比较不优美,但是有的手机Rom对这个默认做了修改,比如红米HM1,默认的就是新页面自右向左滑动出现,自左向右滑动消失。
设置动画有两种方法:
1。利用Activity的方法在代码中设置:
public void overridePendingTransition (int enterAnim, int exitAnim)
Call immediately after one of the flavors ofstartActivity(Intent)orfinish()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的打开关闭动画的更多相关文章
- 设置Activity显示和关闭时的动画效果
设置Activity显示和关闭时的动画效果 通过overridePendingTransition方法可以设置Activity显示和关闭的动画效果.首先需要在res/anim目录中建立相应的动画资源文 ...
- 两个activity的3D翻转动画.md
一.业务需求 这里在公司项目设计时,用到了一个小的需求,就是点击一个按钮然后整个activity的页面进行3d翻转; 二.设计思路 由于是2个activity的之间的翻转动画,就意味着前90度是A页面 ...
- Activity Fragment转场动画
Activity转场动画 先介绍个动画的好例子:https://github.com/lgvalle/Material-Animations Activity的转场动画是通过overridePendi ...
- activity fragment 转场动画
http://www.cnblogs.com/avenwu/p/3372736.html v4 fragment fragmentTransaction.setCustomAnimations(R.a ...
- Android零基础入门第74节:Activity启动和关闭
上一期我们学习了Activity的创建和配置,当时留了一个悬念,如何才能在默认启动的Activity中打开其他新建的Activity呢?那么本期一起来学习如何启动和关闭Activity. 一.概述 经 ...
- 通过暗码去打开/关闭usb debug开关
通过暗码去打开/关闭usb debug开关 通过暗码去打开/关闭usb debug开关1. Description2. Analysis3. Solution4. Summary 1. Descrip ...
- CentOS7使用firewalld打开关闭防火墙与端口(转载)
1.firewalld的基本使用 启动: systemctl start firewalld 查看状态: systemctl status firewalld 停止: systemctl disabl ...
- deepin gala窗口管理器关闭动画
deepin中有两个管理器,一个基于metacity,另一个基于gala,可以用super+tab来进行切换.metacity是不带动画的,而 gala是带动画效果的.但这里有个问题,不知道有些同学上 ...
- Android activity界面跳转动画
实现activity界面跳转动画 1.在startActivity方法之后加入: overridePendingTransition(R.anim.pull_in_right, R.anim.pull ...
随机推荐
- 攻击DotCom小游戏
许久都没写博客了,些许是前段时间有些懈怠,今天来写博客,想记录下做过的事情,怕以后电脑换了,以前做的小项目也跟着丢了,总结下最近做的一个小游戏: 游戏目的:建立一个7X7的网格,选择其中的连续的三格来 ...
- hdu 3934 Summer holiday(凸包最大内接三角形)
求n个点能组成的最大三角形,一发旋转卡壳模板题... #include<algorithm> #include<iostream> #include<cstring> ...
- Redis的同步(主从复制)和Redis Sentinel
Redis的同步可以让其他服务器拥有一个不断更新的数据副本,从而使拥有数据副本的服务器可以处理客户端发出的读请求. 1.Redis同步的方法: 我们可以通过发送SLAVEOF host port命令来 ...
- OAuth 2.0 for MVC, Two Legged Implementation
OAuth 2.0 for MVC, Two Legged Implementation tdupont Fri, Mar 18 2011 9:30 AM 13 OAuth 1.0 was one ...
- wcf 速成,转的啊 第一天
作为WCF速成系列,只介绍些项目开发中常用到的实战知识. 学习wcf,还是对其中的几个术语要了解一下.wcf中有一个ABC的概念,就是 第一: "A" 是地址,就是告诉别人我wcf ...
- Chrome 常用快捷键
20160518 生活常识 Chrome常用操作快捷键 掌握Chrome的常用快捷键,不仅可以节约时间,还能够提高工作效率,最主要还可以装逼.以下是一些常用快捷键: 窗口操作快捷键: ...
- 用C++编写程序,输出两个字符串的最大公共子字符串
#include<iostream> #include<string> using namespace std; int main() { string s_l,s_sh; ...
- Java学习之Java中常用对象
java的几种对象(PO,VO,DAO,BO,POJO)解释 一.PO:persistant object 持久对象,可以看成是与数据库中的表相映射的java对象.最简单的PO就是对应数据库中 ...
- [转]前端CSS规范整理
一.文件规范 1.文件均归档至约定的目录中. 具体要求通过豆瓣的CSS规范进行讲解: 所有的CSS分为两大类:通用类和业务类.通用的CSS文件,放在如下目录中: 基本样式库 /css/core 通用 ...
- PHP EOF(heredoc)的使用
<?php /* Heredoc技术,在PHP手册和技术书籍中一般没有详细讲述,只是提到了这是一种Perl风格的字符串输出技术. 目前一些论坛程序和CMS系统使用了这种技术,前不久看一个朋友的P ...