`

不用线程做Android软件欢迎界面,透明效果,完成后自动跳转

阅读更多

最近在网上看到一些Android软件的欢迎界面做得都挺复杂的(个人觉得),因为一般都用到了线程,接着就想有没有简单一点的办法。然后就有了下文:

 

这个欢迎界面主要是借助Animation动画来实现的(效果如图),不需要用到线程。实现的方法很简单,为动画设置监听就可以了,在动画播放结束时结束欢迎界面并跳转到软件的主界面。

 

  

 

/**
 * 欢迎界面
 * @author 小建枫叶
 *
 */
public class WelcomeActivity extends Activity implements AnimationListener {
	private ImageView  imageView = null;
	private Animation alphaAnimation = null;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		
		super.onCreate(savedInstanceState);
		setContentView(R.layout.welcome);
		imageView = (ImageView)findViewById(R.id.welcome_image_view);
		alphaAnimation = AnimationUtils.loadAnimation(this, R.anim.welcome_alpha);
		alphaAnimation.setFillEnabled(true); //启动Fill保持
		alphaAnimation.setFillAfter(true);  //设置动画的最后一帧是保持在View上面
		imageView.setAnimation(alphaAnimation);
		alphaAnimation.setAnimationListener(this);  //为动画设置监听
 	}
	
	@Override
	public void onAnimationStart(Animation animation) {
		
	}
	
	@Override
	public void onAnimationEnd(Animation animation) {
		//动画结束时结束欢迎界面并转到软件的主界面
		Intent intent = new Intent(this, MainActivity.class);
		startActivity(intent);
		this.finish();
	}
	
	@Override
	public void onAnimationRepeat(Animation animation) {
		
	}
	
	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		//在欢迎界面屏蔽BACK键
		if(keyCode==KeyEvent.KEYCODE_BACK) {
			return false;
		}
		return false;
	}
	
}
 

 动画welcome_alpha.xml

 

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
	android:interpolator="@android:anim/accelerate_interpolator">
	<alpha 
		android:fromAlpha="0.0"
		android:toAlpha="1.0"
		android:duration="2000" 
		/>
	<alpha 
		android:fromAlpha="1.0"
		android:toAlpha="0.0"
		android:startOffset="3000" //延迟3秒再开始
		android:duration="3000" 
		/>
</set>

 

布局welcome.xml

 

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" 
    android:gravity="center_vertical|center_horizontal">
	<ImageView
	    android:id="@+id/welcome_image_view" 
	    android:layout_width="wrap_content"
   		android:layout_height="wrap_content"
   		android:src="@drawable/welcome"
	    />
</LinearLayout>
  • 大小: 6.2 KB
  • 大小: 11.5 KB
10
0
分享到:
评论
2 楼 JACKDG2010 2012-04-18  
学习学习
1 楼 shangdahao 2011-11-13  
用handler会更简单

相关推荐

Global site tag (gtag.js) - Google Analytics