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

在android应用中,其实闪屏是一个很重要的前期

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



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

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

[java]  view plain  copy
 print ? 在CODE上查看代码片 派生到我的代码片
  1. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  2.     xmlns:tools="http://schemas.android.com/tools"  
  3.     android:layout_width="match_parent"  
  4.     android:layout_height="match_parent"  
  5.     android:background="@drawable/splash"  
  6.     tools:context=".SplashActivity" >  
  7.   
  8. </RelativeLayout>  

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

[java]  view plain  copy
 print ? 在CODE上查看代码片 派生到我的代码片
  1. import android.os.Bundle;  
  2. import android.os.Handler;  
  3. import android.app.Activity;  
  4. import android.view.Window;  
  5. import android.view.WindowManager;  
  6.   
  7. public class SplashActivity extends Activity {  
  8.   
  9.     @Override  
  10.     protected void onCreate(Bundle savedInstanceState) {  
  11.         super.onCreate(savedInstanceState);  
  12.           
  13.         getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,  
  14.                 WindowManager.LayoutParams.FLAG_FULLSCREEN);  
  15.         this.requestWindowFeature(Window.FEATURE_NO_TITLE);  
  16.           
  17.         setContentView(R.layout.splash);  
  18.           
  19.         new Handler().postDelayed(new Runnable() {  
  20.             public void run() {  
  21. //              Intent it = new Intent();  
  22. //              it.setClass(SplashActivity.this, Login.class);  
  23. //              startActivity(it);  
  24.                 finish();  
  25.             }  
  26.         }, 1000 * 2);  
  27.     }  
  28.   
  29. }  

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

[java]  view plain  copy
 print ? 在CODE上查看代码片 派生到我的代码片
  1. getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,  
  2.                 WindowManager.LayoutParams.FLAG_FULLSCREEN);  
  3.         this.requestWindowFeature(Window.FEATURE_NO_TITLE);  
利用handler的延迟函数,然后在run方法中写要去的页面

[java]  view plain  copy
 print ? 在CODE上查看代码片 派生到我的代码片
  1. new Handler().postDelayed(new Runnable() {  
  2.             public void run() {  
  3. //              Intent it = new Intent();  
  4. //              it.setClass(SplashActivity.this, Login.class);  
  5. //              startActivity(it);  
  6.                 finish();  
  7.             }  
  8.         }, 1000 * 2);  

 代码下载 


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值