android程序启动画面Splash(方法二)

2009年09月17日  |  10:20 上午分类:android  |  标签:  |  被浏览733次

上一篇文章说了第一种方法。1、使用两个Activity,程序启动时候load第一张Activity,然后由tick触发N秒钟后startActivity另外一张Activity。
2、使用一个Activity,可以用到View.gone() 这个方法。把Acitivity的某些元素移除。代码如下:

androidmanifest.xml就不多说了。先看布局代码:

<?xml version=”1.0″ encoding=”utf-8″?>
<LinearLayout xmlns:android=”http://schemas.android.com/apk/res/android
 android:orientation=”vertical”
 android:layout_width=”fill_parent”
 android:layout_height=”fill_parent”>   
     <LinearLayout android:id=”@+id/splashscreen” android:orientation=”vertical”
          android:layout_width=”fill_parent” android:layout_height=”fill_parent”>
          <ImageView  android:layout_width=”wrap_content”
               android:layout_height=”wrap_content” android:src=”@drawable/splash”
               android:layout_gravity=”center”
               android:layout_marginTop=”130px”/>
          <TextView
               android:id=”@+id/info”
               android:layout_width=”fill_parent”
               android:layout_height=”wrap_content”
               android:gravity=”center”
               android:paddingTop=”10px”
               android:text=”This is a splash!!”/>
     </LinearLayout>     
 <WebView android:id=”@+id/browser”
  android:layout_width=”fill_parent”
  android:layout_height=”fill_parent” android:layout_weight=”1″/>
</LinearLayout>

有一个id为splashscreen 的linearlayout,是程序启动时显现的部分。id为browser是程序的主界面显示部分。

  1. package net.hlovey.s;
  2. import android.app.Activity;
  3. import android.app.AlertDialog;
  4. import android.content.DialogInterface;
  5. import android.content.Intent;
  6. import android.os.Bundle;
  7. import android.os.Handler;
  8. import android.os.Message;
  9. import android.util.Log;
  10. import android.view.LayoutInflater;
  11. import android.view.animation.Animation;
  12. import android.view.animation.AnimationUtils;
  13. import android.widget.LinearLayout;
  14. import android.widget.TextView;
  15. import android.widget.Toast;
  16. public class WebGameActivity extends Activity {
  17.  
  18.   private WebView webView
  19.    
  20.   private Handler mHandler = new Handler();
  21.  
  22.   private static final String TAG = "WebGameActivity";  
  23.   //菜单
  24.   private static final int MENU_RELOAD = Menu.FIRST;
  25.   private static final int MENU_HELP = Menu.FIRST + 1;
  26.   private static final int MENU_ABOUT = Menu.FIRST + 2;
  27.   private static final int MENU_CLOSE = Menu.FIRST + 3;  
  28.   private int staus  = 0
  29.   
  30.   private static final int  STOPSPLASH = 0;
  31.   //time in milliseconds
  32.   private static final long SPLASHTIME = 1000;
  33.   
  34.   private LinearLayout splash;
  35.   private TextView tv;
  36.  
  37.   private Animation myAnimation_Alpha;
  38.   private Animation animatinoGone ;
  39.  
  40.   private Handler splashHandler = new Handler() {
  41.     public void handleMessage(Message msg) {
  42.          switch (msg.what) {
  43.          case STOPSPLASH:
  44.               if( staus == 1 ){               
  45.                 splash.startAnimation(animatinoGone);
  46.                 splash.setVisibility(View.GONE);
  47.                 break;
  48.               }
  49.               sendEmptyMessageDelayed(STOPSPLASH, SPLASHTIME);
  50.          }
  51.          super.handleMessage(msg);
  52.     }
  53. };
  54.  
  55.   @Override
  56.   protected void onCreate(Bundle savedInstanceState) {
  57.     super.onCreate(savedInstanceState);
  58.     getWindow().requestFeature(Window.FEATURE_PROGRESS)//去标题栏
  59.     setContentView(R.layout.main);   
  60.     animatinoGone = AnimationUtils.loadAnimation(this,R.anim.alpha_gone); //动画效果
  61.     myAnimation_Alpha = AnimationUtils.loadAnimation(this,R.anim.alpha_action); //动画效果
  62.    
  63.     splash = (LinearLayout) findViewById(R.id.splashscreen);
  64.     tv = (TextView) findViewById(R.id.info);
  65.     tv.setText("正在建立数据连接");
  66.     splash.startAnimation(myAnimation_Alpha);
  67.    
  68.     Message msg = new Message();
  69.     msg.what = STOPSPLASH;
  70.     splashHandler.sendMessageDelayed(msg, SPLASHTIME);
  71.  
  72. }

代码只贴这么多了,可以多多的深挖。可以自己加上很多效果·········
转载请注明: 本文载自:【猴婆博客】 http://www.hlovey.cn/2009/09/17/android-splash-2.html

========================================================

如非特别声明,本博客所有文章皆为原创,转载时请注明作者及出处,谢谢!
喜欢本文,就收藏到: Del.icio.us Google书签 Digg Live Bookmark Technorati Furl Yahoo书签 Facebook 百度搜藏 新浪ViVi 365Key网摘 天极网摘 和讯网摘 博拉网 POCO网摘 添加到饭否 QQ书签 Digbuzz我挖网

1条评论 关于 “android程序启动画面Splash(方法二)”

  1. android程序启动画面Splash(方法一) - 猴婆博客 发表于: 九月 24th, 2009 9:17 下午

    [...] 网站地图 上一篇:android下载web数据的方法 下一篇:android程序启动画面Splash(方法二) [...]


发表您的评论

您必须 登录 才能发表评论。