(1)我们在MainAcitvity中定义两个textview,用于点击触发切换Activity事件,下面是布局文件代码。

  <LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/top_bg"
android:orientation="horizontal" >
<LinearLayout
android:id="@+id/list_all"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1.0"
android:background="@drawable/btn_bottom_bg"
android:clickable="true"
android:gravity="center"
android:orientation="vertical" >
<TextView
android:id="@+id/tv_all"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableLeft="@drawable/city"
android:drawablePadding="5.0dip"
android:duplicateParentState="true"
android:gravity="center"
android:text="@string/all"
android:textColor="@color/white"
android:textSize="13.5sp" />
</LinearLayout>
<LinearLayout
android:id="@+id/list_school"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1.0"
android:background="@drawable/btn_bottom_bg"
android:clickable="true"
android:gravity="center"
android:orientation="vertical" >
<TextView
android:id="@+id/tv_school"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableLeft="@drawable/location"
android:drawablePadding="5.0dip"
android:duplicateParentState="true"
android:gravity="center"
android:text="@string/school"
android:textColor="@color/white"
android:textSize="13.5sp" />
</LinearLayout>
</LinearLayout>

(2)为textView添加点击事件。重写overridePendingTransition方法,添加切换动画的效果,第一个参数是进入的效果,第二个参数是退出的效果。

TextView tv_all = (TextView) this.findViewById(R.id.tv_all);
tv_all.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent();
intent.setClass(SecondActivity.this, MainActivity.class);
startActivity(intent);
overridePendingTransition(R.anim.slide_in_left,
R.anim.slide_out_right);
}
});

(3)slide_in_left.xml进入的效果

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" >
<translate
android:duration="500"
android:fromXDelta="-50%p"
android:toXDelta="0" />
<alpha
android:duration="500"
android:fromAlpha="0.0"
android:toAlpha="1.0" />
</set>

()slide_out_right.xml退出的效果

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" >
<translate
android:duration="500"
android:fromXDelta="0"
android:toXDelta="50%p" />
<alpha
android:duration="500"
android:fromAlpha="1.0"
android:toAlpha="0.0" />
</set>

Android开发中activity切换动画的实现的更多相关文章

  1. Android Studio之Activity切换动画(三)

    1.上一篇文章"Android Studio之多个Activity的滑动切换(二)"中实现了多个activity之间的滑动切换,可是新切换出的activity大多是从右側进入 2. ...

  2. 详解Android开发中Activity的四种launchMode

    Activity栈主要用于管理Activity的切换.当使用Intent跳转至某个目标Activity,需要根据目标Activity的加载模式来加载. Activity一共有以下四种launchMod ...

  3. Android 5.0 Activity切换动画

    在Androiod5.0中,Google定义了Material Design的规范.而动画切换,能给用户直观的连贯性的体验,也是Google推崇的. 为此,在Android5.0中,Android新支 ...

  4. Android开发中Activity状态的保存与恢复

    当置于后台的Activity因内存紧张被系统自动回收的时候,再次启动它的话他会重新调用onCretae()从而丢失了之前置于后台前的状态. 这时候就要重写Activity的两个方法来保存和恢复状态,具 ...

  5. Android 动画之View动画效果和Activity切换动画效果

    View动画效果: 1.>>Tween动画通过对View的内容进行一系列的图形变换(平移.缩放.旋转.透明度变换)实现动画效果,补间动画需要使用<set>节点作为根节点,子节点 ...

  6. Android 编程下设置 Activity 切换动画

    为 Activity 设置切换动画 我们知道,我们可以在 AndroidManifest.xml 文件中,通过 android:theme 属性设置 Activity 的主题.主题中定义了关于 Act ...

  7. 解决Activity启动黑屏和设置android:windowIsTranslucent不兼容activity切换动画的问题

    在该项目中遇到开Activity之后,黑屏问题,解决的办法是在网上通过设置发现theme和style特性,可以实现. http://www.cnblogs.com/sunzn/p/3407078.ht ...

  8. android开发中关于继承activity类中方法的调用

    android开发中关于继承activity类中的函数,不能在其他类中调用其方法. MainActivity.java package com.example.testmain; import and ...

  9. Android开发中java.lang.RuntimeException: Unable to start activity ComponentInfo{xxx}

    Android开发中java.lang.RuntimeException: Unable to start activity ComponentInfo{xxx}: java.lang.NullPoi ...

随机推荐

  1. jQuery选择器模糊匹配

    <html> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8&quo ...

  2. Fast portable non-blocking network programming with Libevent--转

    Learning Libevent Chapter 0: About this document Chapter 1: A tiny introduction to asynchronous IO. ...

  3. Spring 4.2 annotation event Publisher/Listener

    http://spring.io/blog/2015/02/11/better-application-events-in-spring-framework-4-2 Better applicatio ...

  4. url解析

    window.onload=function(){ var url="http://www.qq.com/index.html?key1=1&key2=2&key3=3&qu ...

  5. 给Chrome和Firefox添加js脚本作为插件的方法

    为了防止无良网站的爬虫抓取文章,特此标识,转载请注明文章出处.LaplaceDemon/ShiJiaqi. http://www.cnblogs.com/shijiaqi1066/p/5973141. ...

  6. [未完成]关于枚举(Enum)

    今天总结一下枚举相关的知识.先附一段关于枚举的代码: package org.talend.core.model.param; import org.talend.core.i18n.Messages ...

  7. mongodb用mongoose取到的对象不能增加属性

    先定义了一个article的schema var mongoose = require('mongoose'); var Schema = mongoose.Schema; exports.schem ...

  8. Freemarker 输出$和html标签等特殊符号

    场景:程序员都不喜欢看文档,而更喜欢抄例子.所以,我们把平台组的组件都做成例子供别人参考.我们前端展示层使用的是freemarker,所以 遇到这个问题,比如我们要让前端显示freemarker自己的 ...

  9. Linux系统下安装ISO文件

    1.在/mnt目录下,创建相应的iso文件夹,例如cd1,cd2. 2.然后,用命令:mount -o loop /home/kinglu/Matlab/matlab1.iso(iso文件路径名) / ...

  10. 目前项目wordpress插件记录

    Restrict User Content WordPress 后台只显示当前登录用户的文章.页面和媒体 Client Dash 可以根据不同的角色生成不同的后台的菜单