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

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

/** * 欢迎界面 * @author 小建枫叶 * */public class WelcomeActivity extends Activity implements AnimationListener {private ImageView  imageView = null;private Animation alphaAnimation = null;@Overrideprotected 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);  //为动画设置监听 }@Overridepublic void onAnimationStart(Animation animation) {}@Overridepublic void onAnimationEnd(Animation animation) {//动画结束时结束欢迎界面并转到软件的主界面Intent intent = new Intent(this, MainActivity.class);startActivity(intent);this.finish();}@Overridepublic void onAnimationRepeat(Animation animation) {}@Overridepublic 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>

更多相关文章

  1. Handler的使用方法――在子线程中更新界面 .
  2. 盛大资深软件工程师谈Android开发经验
  3. 简单新闻客户端APP设计
  4. 基于Socket的Android聊天室
  5. Android开发之UI线程和非UI线程
  6. android用户界面-事件处理
  7. Android异步消息处理机制(2)源码解析
  8. Android应用程序的4个组件
  9. Android(安卓)java面试题收集

随机推荐

  1. Andriod开发必备资料
  2. 关于android WebViewClient的方法解释
  3. Android使用XML全攻略(2)
  4. android Keycode 完全对照表
  5. Android重力感应实现方式简介
  6. 在线音乐播放器
  7. Android安全检查之Root环境检测
  8. Android之 系统启动流程
  9. Android 4.3发布 新增4大改变25日推送升
  10. Android 开发者调查