1.先找到欢迎界面的控件ImageView
2.初始化动画
3.控件ImageView设置步骤2的动画
4.动画设置监听事件,动画结束跳转
淡入淡出动画文件:
<span style="font-size:18px;">fade_in.xml</span>
<span style="font-size:18px;"><?xml version="1.0" encoding="utf-8"?>
<alpha xmlns:android="http://schemas.android.com/apk/res/android"
android:fromAlpha="0.0"
android:toAlpha="1.0"
android:duration="500">
</alpha>
</span>
<span style="font-size:18px;"></span>
<pre class="html" name="code"><span style="font-size:18px;">fade_out.xml</span>
<span style="font-size:18px;"><?xml version="1.0" encoding="utf-8"?>
<alpha xmlns:android="http://schemas.android.com/apk/res/android"
android:fromAlpha="1.0"
android:toAlpha="0.0"
android:duration="500">
</alpha>
</span>
<span style="font-size:18px;"></span>
<span style="font-size:18px;"></span>
<span style="font-size:18px;">fadein.xml</span>
<span style="font-size:18px;"><?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" >
<alpha
android:fromAlpha="0.0"
android:toAlpha="1.0" />
</set>
</span>
欢迎界面布局:
<span style="font-size:18px;"><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.test.MainActivity" >
<ImageView
android:id="@+id/iv"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="fitXY"
android:src="@drawable/welcome" />
</RelativeLayout>
</span>
欢迎界面逻辑代码文件:
<span style="font-size:18px;">package com.example.test;
import android.R.animator;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;
public class MainActivity extends Activity {
ImageView iv;
Animation animation;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
init();
setListener();
}
private void init() {
animation=AnimationUtils.loadAnimation(getBaseContext(), R.anim.fadein);
animation.setDuration(1000);
animation.setFillAfter(true);//设为true之后,界面会停留在动画播放完时的界面
iv=(ImageView) findViewById(R.id.iv);
iv.setAnimation(animation);
}
private void setListener() {
animation.setAnimationListener(new AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
// TODO Auto-generated method stub
}
@Override
public void onAnimationRepeat(Animation animation) {
// TODO Auto-generated method stub
}
@Override
public void onAnimationEnd(Animation animation) {
Intent intent=new Intent();
intent.setClass(getBaseContext(), SecondActivity.class);
startActivity(intent);
overridePendingTransition(R.anim.fade_in, R.anim.fade_out);
finish();
}
});
}
}
</span>