安卓App启动画面
启动界面作为主Activity的layout,一定时间后,启动另一个正式工作的Activity,进入工作界面;
每个Android应用启动之后都会出现一个Splash启动界面,显示产品的LOGO、公司的LOGO或者开发者信息。如果应用程序启动时间比较长,那么启动界面就是一个很好的东西,可以让用户耐心等待这段枯燥的时间。
- 制作Splash界面
突出产品LOGO,产品名称,产品主要特色;
注明产品的版本信息;
注明公司信息或者开发者信息;
背景图片,亦可以用背景颜色代替; - 除了等待还能做点什么
大多数的Splash界面都是会等待一定时间,然后切换到下一个界面;
其实,在这段时间里,可以对系统状况进行检测,比如网络是否通,电源是否充足;
或者,预先加载相关数据;
为了能让启动界面展现时间固定,需要计算执行以上预处理任务所花费的时间,那么:启动界面SLEEP的时间=固定时间-预处理任务时间
1.新建一个splash.xml文件,这个是作为启动界面的
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <ImageView android:layout_height="fill_parent" android:layout_width="fill_parent" android:scaleType="fitCenter" android:src="@drawable/rain"> </ImageView> </LinearLayout>
2.新建一个类start
package com.example.rixin; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.os.Handler; public class start extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.splash); Handler x = new Handler(); x.postDelayed(new splashhandler(), 2000); } class splashhandler implements Runnable{ public void run() { startActivity(new Intent(getApplication(),MainActivity.class)); start.this.finish(); } } }
3.进入AndroidManifest.xml配置为默认的第一启动界面
<application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > <activity android:name="com.example.rixin.start" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name="com.example.rixin.MainActivity"></activity> <activity android:name="com.example.rixin.task"></activity> </application>
至此简单的启动界面就完成了
效果如下:(录屏帧数没选择好,看起来可能有点卡)
想要实现文章开始所说的功能,可以参考http://www.jb51.net/article/36190.htm