【Android开发】Activity切换动画

好久没写博文了,自从ACM退役以后,一直在专注开发应用程序。如果不是今天有博友加我QQ,我都忘记我的博客了,看看以前自己的劳动成果,努力的那些日子历历在目,我决定每周定时更新博文!作为自己前进的动力。

今天学了Activity切换动画与页面切换动画,总结了一下学习笔记:

Activity切换动画:

两个Activity的界面配置文件
activity_main.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

     <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="打开新Activity"
        android:onClick="openActivity"/>

</LinearLayout>

other.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#000000"
    android:orientation="vertical" >

     <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textColor="#FFFFFF"
        android:text="这是新Activity" />

</LinearLayout>

MainActivity.java:

package com.example.activitymove;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;

public class MainActivity extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
	}

	public void openActivity(View v){
		Intent intent=new Intent(this,OtherActivity.class);
		startActivity(intent);

		//实现Activity页面切换动画
		//参数(进来的动画,退出的动画)
		this.overridePendingTransition(R.anim.enteralpha, R.anim.outalpha);
	}

}

OtherActivity.java:

package com.example.activitymove;

import android.app.Activity;
import android.os.Bundle;

public class OtherActivity extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.other);
	}

}

在res/anim/文件夹下有enteralpha.xml和outalpha.xml两个动画配置文件:

enteralpha.xml:

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
     android:shareInterpolator="false">
    <alpha
        android:fromAlpha="0"
        android:toAlpha="1.0"
        android:duration="5000"
    />

</set>

outalpha.xml:

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
     android:shareInterpolator="false">
    <alpha
        android:fromAlpha="1.0"
        android:toAlpha="0"
        android:duration="5000"
    />

</set>

效果:点击MainActivity的按钮,画面慢慢消失,OtherActivity逐渐显现出来

(将配置文件换成其他的动画效果也可以,本例子使用的是淡入淡出的动画效果)

转载请注明出处!程序猿之洞:http://blog.csdn.net/acmman

时间: 2024-07-28 23:16:35

【Android开发】Activity切换动画的相关文章

Android Activity切换动画详解及实例

Android Activity切换动画 Android Activity切换动画是指从Activity A 跳转至Activity B的时候,Activity A 有退出动画,Activity B 有进入动画.这个动画的实现很简单,在startActivity(intent)之后调overridePendingTransition ()这个方法就行.比如实现淡入淡出的效果如下: Intent i = new Intent(ActivityA.this,ActivityB.class); Sta

animation-android activity 切换动画问题

问题描述 android activity 切换动画问题 我自定义Activity切换动画,但是没有效果,求助时什么问题?用的Theme,没有用OverridePendingAnimation 这是代码 <activity android:name=".activities.CardCommentActivity" android:screenOrientation="portrait" android:theme="@style/cardComme

app-android activity切换动画和墙纸冲突

问题描述 android activity切换动画和墙纸冲突 主题里面设置了属性true 的时候,使用overridePendingTransition(app_in,app_exit); app_exit 动画将不会被播放,有什么办法可以解决 解决方案 Android Activity切换动画android activity 切换+动画android activity切换动画

Android开发之背景动画简单实现方法

本文实例讲述了Android开发之背景动画简单实现方法.分享给大家供大家参考,具体如下: 1.先创建动画层,有三张图片 <?xml version="1.0" encoding="utf-8"?> <animation-list xmlns:android="http://schemas.android.com/apk/res/android" > <item android:drawable="@draw

Android开发 Activity和Fragment详解_Android

1.Activity的生命周期 1)多个Activity组成Activity栈,当前活动位于栈顶.我们先来看看各种Activity基类的类图: 当Activity类定义出来之后,这个Activity何时被实例化.它所包含的方法何时被调用,这些都不是由开发者所决定的,都应该由Android系统来决定. 下面我们来看一下Activity的生命周期: 2.Activity的用法 1)启动.关闭Activity // 首先需要创建启动的Activity对应的Intent Intent intent =

Activity切换动画--模糊、水波纹、折叠效果 ...

Enhance Activity switch animation. source code : https://github.com/dkmeteor/ActivityAnimationLib 这是2个Activity切换动画,提供了单独的一套接口,可以实现基于Canvas . Martrix .或 Bitmap级的动画效果   目前提供(右上角menu切换): water folder blur skew close split 6种动画效果. split是基于ObjectAnimation

android 开发activity如何向多个不同fragment 进行通信

问题描述 android 开发activity如何向多个不同fragment 进行通信 最近开发android ,需要一个activity 向不同的fragment 发送消息,知道的告诉小弟一声. 解决方案 setArguments方法 解决方案二: 可以用刘上的setArguments来设置,也可以用APP这个全局变量的类来专递数据,写一个APP类的单例模式,然后获取的值存到这里,在fragment里面调用就可以了 解决方案三: fragment是需要依赖activity的,fragments

Android Activity切换动画效果的修改

Activity的动画效果在\android\frameworks\base\core\res\res\values下的stlyes.xml,themes.xml两个文件中有定义. 但是有时这些效果未必能满足你的要求,需要自己定义styles.xml来实现这个功能.  Activity去掉默认的动画效果方法:  1.重写Activity的Them中的windowAnimationStyle相关属性,并保存在res/values/styles.xml  <?xml version="1.0&

[Android1.5]Android2.0版本以下Activity切换动画效果

前言 在Android 2.0版本以上做Activity切换时的动画效果是很容易的,可以调用overridePendingTransition函数,一行代码搞定,当然配置动画效果的xml文件是少不了的,但是在2.0版本以下是没有这个函数的,如何方便的做动画效果呢?有说用ViewFlipper或者getWindow().setWindowAnimations,但是这里都没有成功,用了一个取巧的办法,但是效果还不错:)   声明 欢迎转载,但请保留文章原始出处:)  博客园:http://www.c