带动画的欢迎界面的实现

1.先找到欢迎界面的控件ImageView

2.初始化动画

3.控件ImageView设置步骤2的动画

4.动画设置监听事件,动画结束跳转

 

 

 

淡入淡出动画文件:

fade_in.xml




 
fade_out.xml
 
  




 
 
fadein.xml


    





 

 

欢迎界面布局:



    



 

 

欢迎界面逻辑代码文件:

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();
			}
		});
	}

}


 

 

 

 

你可能感兴趣的:(欢迎,动画,安卓)