您的位置:首页 > 移动开发 > Android开发

Android进阶篇之引导页系列之Splash闪屏Log

2016-02-23 15:23 573 查看
在android应用中,其实闪屏是一个很重要的前期

先上效果图:就是一个页面



嗯,闪屏第一要做的就是展现自己的Logo,如果Logo好看,一眼就能留住用户,如果Logo和我的名字一样,

,用户肯定是屈指可数啊;第二,也是闪屏最重要的作用,就是利用闪屏的时间来做很多数据加载操作,这个也不难想到,如果直接进入数据比较多的主页时,那加载主页的承载负量就特别大,甚至会导致ANR<Application
no responsed>,所以基本上上线的产品大多数都会在闪屏的时候加载数据;第三,检查更新。。。

splash.xml文件,很简单,就是一个空的,设置背景,如果想设置自己的Logo可以直接写在里面

[java] view
plain copy

print?





<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"

xmlns:tools="http://schemas.android.com/tools"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:background="@drawable/splash"

tools:context=".SplashActivity" >

</RelativeLayout>

SplashActivity.java,也很简单,没什么可说的。

[java] view
plain copy

print?





import android.os.Bundle;

import android.os.Handler;

import android.app.Activity;

import android.view.Window;

import android.view.WindowManager;

public class SplashActivity extends Activity {

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,

WindowManager.LayoutParams.FLAG_FULLSCREEN);

this.requestWindowFeature(Window.FEATURE_NO_TITLE);

setContentView(R.layout.splash);

new Handler().postDelayed(new Runnable() {

public void run() {

// Intent it = new Intent();

// it.setClass(SplashActivity.this, Login.class);

// startActivity(it);

finish();

}

}, 1000 * 2);

}

}

下面的代码,是将SplashActivity页面设置全屏,没有状态栏

[java] view
plain copy

print?





getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,

WindowManager.LayoutParams.FLAG_FULLSCREEN);

this.requestWindowFeature(Window.FEATURE_NO_TITLE);

利用handler的延迟函数,然后在run方法中写要去的页面

[java] view
plain copy

print?





new Handler().postDelayed(new Runnable() {

public void run() {

// Intent it = new Intent();

// it.setClass(SplashActivity.this, Login.class);

// startActivity(it);

finish();

}

}, 1000 * 2);

代码下载
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: