用Animation动画实现Android应用的欢迎界面


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

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

免费下载地址在 http://linux.bkjia.com/

用户名与密码都是www.bkjia.com

具体下载目录在 /2012年资料/2月/22日/用Animation动画实现Android应用的欢迎界面/

  

  1. /**  
  2.  * 欢迎界面  
  3.  * @author 小建枫叶  
  4.  *  
  5.  */  
  6. public class WelcomeActivity extends Activity implements AnimationListener {   
  7.     private ImageView  imageView = null;   
  8.     private Animation alphaAnimation = null;   
  9.        
  10.     @Override  
  11.     protected void onCreate(Bundle savedInstanceState) {   
  12.            
  13.         super.onCreate(savedInstanceState);   
  14.         setContentView(R.layout.welcome);   
  15.         imageView = (ImageView)findViewById(R.id.welcome_image_view);   
  16.         alphaAnimation = AnimationUtils.loadAnimation(this, R.anim.welcome_alpha);   
  17.         alphaAnimation.setFillEnabled(true); //启动Fill保持   
  18.         alphaAnimation.setFillAfter(true);  //设置动画的最后一帧是保持在View上面   
  19.         imageView.setAnimation(alphaAnimation);   
  20.         alphaAnimation.setAnimationListener(this);  //为动画设置监听   
  21.     }   
  22.        
  23.     @Override  
  24.     public void onAnimationStart(Animation animation) {   
  25.            
  26.     }   
  27.        
  28.     @Override  
  29.     public void onAnimationEnd(Animation animation) {   
  30.         //动画结束时结束欢迎界面并转到软件的主界面   
  31.         Intent intent = new Intent(this, MainActivity.class);   
  32.         startActivity(intent);   
  33.         this.finish();   
  34.     }   
  35.        
  36.     @Override  
  37.     public void onAnimationRepeat(Animation animation) {   
  38.            
  39.     }   
  40.        
  41.     @Override  
  42.     public boolean onKeyDown(int keyCode, KeyEvent event) {   
  43.         //在欢迎界面屏蔽BACK键   
  44.         if(keyCode==KeyEvent.KEYCODE_BACK) {   
  45.             return false;   
  46.         }   
  47.         return false;   
  48.     }   
  49.        
  50. }  
  • 1
  • 2
  • 下一页

相关内容