先创建2个activity
配置对应的布局文件和清单文件
我使用了2个透明度动画效果,放在res下的anim文件夹下
<?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"
android:duration="5000"
/>
</set>
和
<?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>
主activity
package cn.wonders.animation;
import android.support.v7.app.ActionBarActivity;
import android.view.View;
import android.content.Intent;
import android.os.Bundle;
public class MainActivity extends ActionBarActivity {
@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切换动画效果
overridePendingTransition(R.anim.enteralpha, R.anim.outalpha);
}
}
布局
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/first_activity"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/open"
android:onClick="openActivity"
/>
</LinearLayout>
另一个activity
package cn.wonders.animation;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
public class OtherActivity extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.other);
}
}
布局
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/second_activity"
/>
</LinearLayout>