概述每个Android应用程序
启动之后都会出现一个Splash启动界面,显示产品LOGO、公司LOGO或者开发者信息。如果应用程序启动时间比较长,那么启动界面就是一个很好的东西,可以让用户耐心等待这段枯燥的时间,提高用户体验。1.splash.xml布局文件12345678910111213<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"tools:context=".SplashActivity" ><ImageViewandroid:layout_width="match_parent"android:layout_height="match_parent"android:background="@drawable/welcome_android"android:scaleType="fitCenter" /></RelativeLayout>2.SplashActivity类,使用Handler的postDelayed方法,3秒后执行跳转到主视图12345678910111213141516171819202122232425262728293031323334353637383940414243package cn.eoe.leigo.splash;import android.app.Activity;import android.content.Intent;import android.os.Bundle;import android.os.Handler;/**** @{#} SplashActivity.java Create on 2013-5-2 下午9:10:01** class desc: 启动
画面** <p>Copyright: Copyright(c) 2013 </p>* @Version 1.0* @Author <a href="mailto:gaolei_xj@163.com">Leo</a>***/public class SplashActivity extends Activity {//延迟3秒private static final long SPLASH_DELAY_MILLIS = 3000;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.splash);// 使用Handler的postDelayed方法,3秒后执行跳转到MainActivitynew Handler().postDelayed(new Runnable() {public void run() {goHome();}}, SPLASH_DELAY_MILLIS);}private void goHome() {Intent intent = new Intent(SplashActivity.this, MainActivity.class);SplashActivity.this.startActivity(intent);SplashActivity.this.finish();}}3.配置AndroidManifest.xml123456789101112131415161718192021222324252627282930<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android"package="cn.eoe.leigo.splash"android:versionCode="1"android:versionName="1.0" ><uses-sdkandroid:minSdkVersion="10"android:targetSdkVersion="10" /><applicationandroid:icon="@drawable/logo"android:label="@string/app_name" ><activityandroid:name=".SplashActivity"android:configChanges="keyboardHidden"android:label="@string/app_name"android:launchMode="singleTask"android:screenOrientation="portrait"android:theme="@android:style/Theme.NoTitleBar.Fullscreen" ><intent-filter><action android:name="android.intent.action.MAIN" /><category android:name="android.intent.category.LAUNCHER" /></intent-filter></activity><activity android:name=".MainActivity" /></application></manifest>
每个AndroID应用程序启动之后都会出现一个Splash启动界面,显示产品logo、公司logo或者开发者信息。如果应用程序启动时间比较长,那么启动界面就是一个很好的东西,可以让用户耐心等待这段枯燥的时间,提高用户体验。
1.splash.xml布局文件
<span ><ImageV<a href="https://m.jb51.cc/tag/IE/" target="_blank" >IE</a>w</span> <span >andro<a href="https://m.jb51.cc/tag/ID/" target="_blank" >ID</a>:layout_w<a href="https://m.jb51.cc/tag/ID/" target="_blank" >ID</a>th=</span><span >"match_parent"</span> <span >andro<a href="https://m.jb51.cc/tag/ID/" target="_blank" >ID</a>:layout_height=</span><span >"match_parent"</span> <span >andro<a href="https://m.jb51.cc/tag/ID/" target="_blank" >ID</a>:background=</span><span >"@drawable/welcome_andro<a href="https://m.jb51.cc/tag/ID/" target="_blank" >ID</a>"</span> <span >andro<a href="https://m.jb51.cc/tag/ID/" target="_blank" >ID</a>:scaleType=</span><span >"fitCenter"</span> <span >/></span>
<span >
2.SplashActivity类,使用Handler的postDelayed方法,3秒后执行跳转到主视图
<span >import
<span >androID.app.Activity<span >;
<span >import <span >androID.content.Intent<span >;
<span >import <span >androID.os.Bundle<span >;
<span >import <span >androID.os.Handler<span >;<span >/*
<span >
<span > @{#} SplashActivity.java Create on 2013-5-2 下午9:10:01
<span >
<span > class desc: 启动画面
<span >
<span > copyright: copyright(c) 2013
<span > @Version 1.0
<span > @Author <a href="mailto:gaolei_xj@163.com">Leo
<span >
<span >
<span > /
<span >public <span >class <span >SplashActivity <span >extends <span >Activity <span >{
<span >//延迟3秒 </span><span >private</span> <span >static</span> <span >final</span> <span >long</span> <span >SPLASH_DELAY_MIL<a href="https://m.jb51.cc/tag/li/" target="_blank" >li</a>S</span> <span >=</span> <span >3000</span><span >;</span><span >@Overr<a href="https://m.jb51.cc/tag/ID/" target="_blank" >ID</a>e</span><span >protected</span> <span >vo<a href="https://m.jb51.cc/tag/ID/" target="_blank" >ID</a></span> <span >onCreate</span><span >(</span><span >Bundle</span> <span >savedInstanceState</span><span >)</span> <span >{</span> <span >super</span><span >.</span><span >onCreate</span><span >(</span><span >savedInstanceState</span><span >);</span> <span >setContentV<a href="https://m.jb51.cc/tag/IE/" target="_blank" >IE</a>w</span><span >(</span><span >R</span><span >.</span><span >layout</span><span >.</span><span >splash</span><span >);</span> <span >// <a href="https://m.jb51.cc/tag/shiyong/" target="_blank" >使用</a>Handler的postDelayed<a href="https://www.jb51.cc/tag/fangfa/" target="_blank" >方法</a>,3秒<a href="https://www.jb51.cc/tag/houzhixing/" target="_blank" >后执行</a><a href="https://www.jb51.cc/tag/tiaozhuan/" target="_blank" >跳转</a>到MainActivity </span> <span >new</span> <span >Handler</span><span >().</span><span >postDelayed</span><span >(</span><span >new</span> <span >Runnable</span><span >()</span> <span >{</span> <span >pub<a href="https://m.jb51.cc/tag/li/" target="_blank" >li</a>c</span> <span >vo<a href="https://m.jb51.cc/tag/ID/" target="_blank" >ID</a></span> <span >run</span><span >()</span> <span >{</span> <span >goHome</span><span >();</span> <span >}</span> <span >},</span> <span >SPLASH_DELAY_MIL<a href="https://m.jb51.cc/tag/li/" target="_blank" >li</a>S</span><span >);</span><span >}</span><span >private</span> <span >vo<a href="https://m.jb51.cc/tag/ID/" target="_blank" >ID</a></span> <span >goHome</span><span >()</span> <span >{</span> <span >Intent</span> <span >intent</span> <span >=</span> <span >new</span> <span >Intent</span><span >(</span><span >SplashActivity</span><span >.</span><span >this</span><span >,</span> <span >MainActivity</span><span >.</span><span >class</span><span >);</span> <span >SplashActivity</span><span >.</span><span >this</span><span >.</span><span >startActivity</span><span >(</span><span >intent</span><span >);</span> <span >SplashActivity</span><span >.</span><span >this</span><span >.</span><span >finish</span><span >();</span><span >}</span>
<span >}
3.配置AndroIDManifest.xml
<span ><</span><span >uses</span><span >-</span><span >sdk</span> <span >andro<a href="https://m.jb51.cc/tag/ID/" target="_blank" >ID</a>:</span><span >minSdkVersion</span><span >=</span><span >"10"</span> <span >andro<a href="https://m.jb51.cc/tag/ID/" target="_blank" >ID</a>:</span><span >targetSdkVersion</span><span >=</span><span >"10"</span> <span >/></span><span ><</span><span >app<a href="https://m.jb51.cc/tag/li/" target="_blank" >li</a>cation</span> <span >andro<a href="https://m.jb51.cc/tag/ID/" target="_blank" >ID</a>:</span><span >icon</span><span >=</span><span >"@drawable/<a href="https://www.jb51.cc/tag/logo/" target="_blank" >logo</a>"</span> <span >andro<a href="https://m.jb51.cc/tag/ID/" target="_blank" >ID</a>:</span><span >label</span><span >=</span><span >"@string/app_<a href="https://m.jb51.cc/tag/name/" target="_blank" >name</a>"</span> <span >></span> <span ><</span><span >activity</span> <span >andro<a href="https://m.jb51.cc/tag/ID/" target="_blank" >ID</a>:</span><span ><a href="https://m.jb51.cc/tag/name/" target="_blank" >name</a></span><span >=</span><span >".SplashActivity"</span> <span >andro<a href="https://m.jb51.cc/tag/ID/" target="_blank" >ID</a>:</span><span >con<a href="https://www.jb51.cc/tag/fig/" target="_blank" >fig</a>Changes</span><span >=</span><span >"keyboardH<a href="https://m.jb51.cc/tag/ID/" target="_blank" >ID</a>den"</span> <span >andro<a href="https://m.jb51.cc/tag/ID/" target="_blank" >ID</a>:</span><span >label</span><span >=</span><span >"@string/app_<a href="https://m.jb51.cc/tag/name/" target="_blank" >name</a>"</span> <span >andro<a href="https://m.jb51.cc/tag/ID/" target="_blank" >ID</a>:</span><span >launchMode</span><span >=</span><span >"singleTask"</span> <span >andro<a href="https://m.jb51.cc/tag/ID/" target="_blank" >ID</a>:</span><span >scree<a href="https://www.jb51.cc/tag/nor/" target="_blank" >nor</a><a href="https://m.jb51.cc/tag/IE/" target="_blank" >IE</a>ntation</span><span >=</span><span >"portrait"</span> <span >andro<a href="https://m.jb51.cc/tag/ID/" target="_blank" >ID</a>:</span><span ><a href="https://m.jb51.cc/tag/theme/" target="_blank" >theme</a></span><span >=</span><span >"@andro<a href="https://m.jb51.cc/tag/ID/" target="_blank" >ID</a>:style/<a href="https://m.jb51.cc/tag/theme/" target="_blank" >theme</a>.No<a href="https://m.jb51.cc/tag/Title/" target="_blank" >Title</a><a href="https://m.jb51.cc/tag/bar/" target="_blank" >bar</a>.F<a href="https://m.jb51.cc/tag/ul/" target="_blank" >ul</a>lscreen"</span> <span >></span> <span ><</span><span >intent</span><span >-</span><span >filter</span><span >></span> <span ><</span><span >action</span> <span >andro<a href="https://m.jb51.cc/tag/ID/" target="_blank" >ID</a>:</span><span ><a href="https://m.jb51.cc/tag/name/" target="_blank" >name</a></span><span >=</span><span >"andro<a href="https://m.jb51.cc/tag/ID/" target="_blank" >ID</a>.intent.action.MAIN"</span> <span >/></span> <span ><</span><span ><a href="https://m.jb51.cc/tag/category/" target="_blank" >category</a></span> <span >andro<a href="https://m.jb51.cc/tag/ID/" target="_blank" >ID</a>:</span><span ><a href="https://m.jb51.cc/tag/name/" target="_blank" >name</a></span><span >=</span><span >"andro<a href="https://m.jb51.cc/tag/ID/" target="_blank" >ID</a>.intent.<a href="https://m.jb51.cc/tag/category/" target="_blank" >category</a>.LAUNCHER"</span> <span >/></span> <span ></</span><span >intent</span><span >-</span><span >filter</span><span >></span> <span ></</span><span >activity</span><span >></span> <span ><</span><span >activity</span> <span >andro<a href="https://m.jb51.cc/tag/ID/" target="_blank" >ID</a>:</span><span ><a href="https://m.jb51.cc/tag/name/" target="_blank" >name</a></span><span >=</span><span >".MainActivity"</span> <span >/></span><span ></</span><span >app<a href="https://m.jb51.cc/tag/li/" target="_blank" >li</a>cation</span><span >></span>
<span ></
<span >manifest<span >>
以上是内存溢出为你收集整理的Android启动画面实现全部内容,希望文章能够帮你解决Android启动画面实现所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
评论列表(0条)