android程序启动画面实现

 

在应用程序中经常用到启动画面,会启动一个后台线程为主程序的运行准备资源。

Android要实现启动画面可以这样做:

这是splash.xml布局文件的代码

1<LinearLayout
3  android:layout_height="fill_parent" android:layout_width="fill_parent" android:orientation="vertical">
4<ImageView android:layout_height="fill_parent" android:layout_width="fill_parent" android:scaleType="fitCenter" android:src="@drawable/splash"></ImageView>
5</LinearLayout>

 放一个ImageView加载启动画面图片

 SplashActivity作为主视图启动

01/** Called when the activity is first created. */
02    @Override
03    public void onCreate(Bundle savedInstanceState) {
04        super.onCreate(savedInstanceState);
05        setContentView(R.layout.splash);
06        Handler x = new Handler();
07        x.postDelayed(new splashhandler(), 2000);
08          
09    }
10    class splashhandler implements Runnable{
11  
12        public void run() {
13            startActivity(new Intent(getApplication(),MainActivity.class));
14            SplashActivity.this.finish();
15        }
16          
17    }

加载后使用Handler的postDelayed方法,2秒后执行跳转到主视图

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值