Android应用启动画面
原文地址:
【Android】应用启动画面 - 空客的日志 - 网易博客
http://blog.163.com/da7_1@126/blog/static/104072678201291921028637/
几乎所有的Android应用程序都会有一个启动画面,展示自己的LOGO,本版信息,或者更人性化一点的,在很长的加载信息中,变换一些显示的文字等,让无聊的等待时间添加点调味剂。
具体实现来说,应该创建一个没有Title的Activity,显示图片,文字。其中创建新的线程去加载数据,检测设备的良好等,等一切就绪的时候启动新的Activity。
AndroidManifast.xml
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.load3" android:versionCode="1" android:versionName="1.0" > <uses-sdk android:minSdkVersion="10" android:targetSdkVersion="19" /> <application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > <activity android:name=".LoadActivity" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest>
其中,声明两个Activity,一个用来作为启动画面,另外一个是启动之后,显示的主画面。
android:screenOrientation="portrait" //屏幕始终纵向
"landscape" //屏幕始终横向
android:theme="@android:style/Theme.NotitleBar" //屏幕没有标题栏
load.xml
<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:gravity="center|center" android:orientation="vertical" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context="com.example.load3.LoadActivity" android:background="@drawable/load" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/hello_world" /> </RelativeLayout>
该load.xml是启动Activity的样式表达,其中
android:background="@drawable/load" //设置load.png图片为背景图
LoadActivity.java
package com.example.load3; import android.support.v7.app.ActionBarActivity; import android.content.Intent; import android.graphics.PixelFormat; import android.os.Bundle; import android.os.Handler; import android.view.Menu; import android.view.MenuItem; import android.view.WindowManager; public class LoadActivity extends ActionBarActivity { private static final int LOAD_DISPLAY_TIME = 1500; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); getWindow().setFormat(PixelFormat.RGBA_8888); getWindow().addFlags(WindowManager.LayoutParams.FLAG_DITHER); setContentView(R.layout.load); new Handler().postDelayed(new Runnable() { public void run() { /* Create an Intent that will start the Main WordPress Activity. */ Intent mainIntent = new Intent(LoadActivity.this, LoadActivity.class); LoadActivity.this.startActivity(mainIntent); LoadActivity.this.finish(); } }, LOAD_DISPLAY_TIME); //1500 for release } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.load, menu); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { // Handle action bar item clicks here. The action bar will // automatically handle clicks on the Home/Up button, so long // as you specify a parent activity in AndroidManifest.xml. int id = item.getItemId(); if (id == R.id.action_settings) { return true; } return super.onOptionsItemSelected(item); } }
其中,Handler().postDelayed(Runnable r, long delayMillis)
//Causes the Runnable r to be added to the message queue, to be run after the specified amount of time elapses.
现在的代码只实现了很简单Load页面的显示。
欢迎访问我的的博客:www.wshunli.com
-------------------
已迁移文章:
VMware 12安装Mac OS X 10.10
http://www.wshunli.com/posts/65583447.html
Tomcat安装配置