android 启动界面

在启动一个app时常会有一个启动界面,在ios中直接设置lunch image就行了。不过在android想要实现这种效果就需要代码人为的设置啦。思路也很简单,在启动View只有一张图,让其自己休眠2秒左右的时间,然后跳进mianActivity的主界面就可以了。看代码:

lunch.xml

<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_height="fill_parent" 
  android:layout_width="fill_parent" 
  android:orientation="vertical">
    <ImageView 
        android:layout_height="fill_parent" 
        android:layout_width="fill_parent" 
        android:scaleType="fitXY"
        android:src="@drawable/lunch">
    </ImageView>
</LinearLayout>

lunchView.java

package com.gdou.gxk;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;


public class LunchView extends Activity{

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.lunch);
        Handler x = new Handler();
        x.postDelayed(new lunchhandler(), 2000);
        
    }
    
    class lunchhandler implements Runnable{

        public void run() {
            startActivity(new Intent(getApplication(),LogInView.class));
            LunchView.this.finish();
        }
        
    }
}

其中的logInView就是我的程序的主界面啦,这样就有了如iphone的lunch image的效果,单纯只为效果而已。

最后要注意在你的配置文件AndroidManifest中要把初始界面改成lunchView的。这样就行啦!!!

 

update:

 由于项目中需要lunchView之后的logInView有判断(如果数据库有保存用户的话直接跳转到相关的内容)。这时候就有问题啦,出现了在跳转到内容界面之前会logIn的会先出现,闪一下。(我的判断是在LoginView的OnCreate中判断的)。在模拟器运行时,又是1.6的没有这种情况,2.2  4.0 的都有这种情况。

最终没办法,找不出像iphone的在view出来前就做的方法,只能放弃上面所说的方法,采用另外一种给为巧妙的方法:

即lunchImage放在loginView中,只要一张覆盖整屏的图片,在“lunch”(睡眠2秒,这里要使用异步类,异步停2秒后回到主线程)之后把image的属性设为Gone即可。

posted on 2012-07-18 14:32  老Zhan  阅读(3247)  评论(0编辑  收藏  举报