«

App启动界面效果设计

时间:2024-3-2 17:13     作者:韩俊     分类: Html+Css


转载请标明出处:http://blog.csdn.net/u012637501/article/details/45746617

每个Android应用启动之后都会出现一个Splash启动界面,大多数的Splash界面都是会等待一定时间,然后切换到下一个界面。但如果app启动时间过长,可使用启动界面让用户耐心等待这段枯燥的时间。Splash界面一般用于显示产品的LOGO、产品名称、版本信息等,也可以完成对系统状况的检测,如网络是否连通、电源是否充足、检测新版本等,也可以预先加载相关数据。启动界面SLEEP的时间=固定时间-预处理任务时间。

一、为APP创建一个简单的启动界面

所谓简单的启动界面,即界面只用于显示产品的LOGO、产品名称等常规信息,不做系统状态检测或数据加载的操作。设计方法如下:实现两activity,一个是SplashActivity,用来做启动画面,另一个是将要跳转的Activity。通过创建一个新的线程,延迟指定的时间再执行Activity的跳转,并调用finish方法结束当前启动activity。

实例:高仿QQ启动界面
1.src/.../WelcomeActivity.java

package com.example.qq2012;
import android.app.Activity; import android.content.Intent;
import android.os.Bundle; import android.view.Window;
/欢迎动画/ public class WelcomeActivity extends Activity {
protected void onCreate(Bundle savedInstanceState) { // requestWindowFeature(Window.FEATURE_NO_TITLE); //设置显示窗口界面特征,此时为窗口无标题
super.onCreate(savedInstanceState); setContentView(R.layout.welcome);
final Intent intent = new Intent(WelcomeActivity.this,LoginActivity.class); //设置一个用于启动新Activity的"意图" intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); //使系统为需要启动的Activity寻找与当前Activity不同的任务栈
new Thread(new Runnable(){ //创建一个新的线程来显示欢迎动画,指定时间后结束,跳转至指定界面 public void run() {
try { Thread.sleep(3000); //欢迎界面启动持续时间
getApplicationContext().startActivity(intent); //启动新的界面,获取应用的上下文,生命周期是整个应用,应用结束才会结束 finish(); //结束欢迎界面activity
} catch (InterruptedException e) { e.printStackTrace();
} }
}).start(); }
}

2.res/layout/welcome.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android&quot;
android:layout_width="match_parent" android:layout_height="match_parent"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen" android:background="@drawable/splash">
</LinearLayout>

分析说明:
(1)隐藏应用标题方法
a.在显示的布局文件中,添加 android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
b.在逻辑代码setContentView(R.layout.login)之前添加requestWindowFeature(Window.FEATURE_NO_TITLE);
(2)调用 Activity.finish()方法时,结果和用户按下 BACK 键一样:告诉 Activity Manager 该 Activity 实例完成了相应的工作,可以被“回收”。SplashActivity 从 Active 状态转换 Stoped
状态,并被系统从栈中移除,标志可以被“回收”。

(3)创建一个新的线程完成界面跳转,两种方法:
方法一:
new Thread(new Runnable(){
public void run() {
Thread.sleep(3000);
//延时时间
.....
finish();

}
方法二:
new Handler().postDelayed(new Runnable() {
public void run() {
........
SplashActivity.this.finish();
}
}, 3000);
说明:
Handler().postDelayed 是延迟指定的时间再执行
Handler类主要可以使用如下3个方法来设置执行Runnable对象的时间:
>立即执行Runnable对象
public final boolean post(Runnable r);
>在指定的时间(uptimeMillis)执行Runnable对象
public final boolean postAtTime(Runnable r, long uptimeMillis);
>在指定的时间间隔(delayMillis)执行Runnable对象
public final boolean postDelayed(Runnable r, long delayMillis);
运行结果:


二、自定义复杂启动界面设计
在启动界面友好展示的同时,后台可以做很多操作,比如系统检测,预加载数据等,这些后台操作可以使用AsyncTask来实现。

1.Splash启动界面设计,res/layout/welcome.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android&quot;
android:layout_width="match_parent" android:layout_height="match_parent"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen" android:background="#FFFFFF">
<!--第一级 --> <TextView
android:id="@+id/copy_right" android:layout_height="wrap_content"
android:layout_width="wrap_content" android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true" android:padding="12dp"
android:text="By 老蒋良心出品"/> <!-- 第一级 -->
<RelativeLayout android:layout_width="fill_parent"
android:layout_height="fill_parent"> <!-- 第二级 -->
<LinearLayout android:layout_width="wrap_content"
android:layout_height="wrap_content" android:orientation="vertical"
android:layout_centerInParent="true"> <!-- logo图片 -->
<ImageView android:id="@+id/logoImage"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:src="@drawable/logo" android:layout_gravity="center_horizontal"
android:background="#ffffff"/> <!-- 产品名称、版本号 -->
<LinearLayout android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_marginTop="20dp"
android:orientation="horizontal"> <TextView
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:padding="6dip" android:text="创新生活app"
android:textStyle="bold" android:textSize="20sp"/>
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content" android:padding="3dip"
android:text="V1.0" android:textStyle="bold"
android:textSize="15sp"/> </LinearLayout>
<!-- 分隔线 --> <View
android:layout_width="fill_parent" android:layout_height="1dp"
android:layout_marginLeft="17dp" android:layout_marginRight="17dp"
android:background="#dddddd"/> <!-- 内容描述 -->
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="center_horizontal" android:padding="6dip"
android:text="科技创新,振兴中华." android:textSize="13sp"/>
<ProgressBar android:id="@+id/refresh_list_footer_progressbar" android:layout_width="24dip"
android:layout_height="24dip" style="@android:attr/progressBarStyleLargeInverse"
android:layout_gravity="center"> </ProgressBar>
</LinearLayout> </RelativeLayout>

2.后台处理,SplashActivity.java

public class SplashActivity extends Activity {
@Override protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); setContentView(R.layout.splash);
new AsyncTask<Void, Void, Integer>() { //后台操作
protected Integer doInBackground(Void... params) { int result;
long startTime = System.currentTimeMillis(); result = loadingCache();
long loadingTime = System.currentTimeMillis() - startTime; if (loadingTime < SHOW_TIME_MIN) {
try { Thread.sleep(SHOW_TIME_MIN - loadingTime);
} catch (InterruptedException e) { e.printStackTrace();
} }
return result; } //操作后台操作的结果
@Override protected void onPostExecute(Integer result) {
// ... ... Intent intent = new Intent();
intent.setClassName(SplashActivity.this, getString(R.string.splash_out_activity)); startActivity(intent);
finish(); //两个参数分别表示进入的动画,退出的动画
overridePendingTransition(R.anim.fade_in, R.anim.fade_out); }.execute(new Void[]{});
} private int loadingCache()
{ }
。。。。。 }




参考资料:
http://blog.csdn.net/wangjinyu501/article/details/7643396
http://www.maopiaopiao.com/article/36190.htm

标签: javascript html css

热门推荐