android幾種歡迎界面的實現 .

1.用handler的postDelayed實現

轉載自:http://www.eoeandroid.com/blog-535302-2331.html

  1. <SPAN style="FONT-SIZE: 18px">每個Android應用啓動之後都會出現一個Splash啓動界面,顯示產品的LOGO、公司的LOGO或者開發者信息。如果應用程序啓動時間比較長,那麼啓動界面就是一個很好的東西,可以讓用戶耐心等待這段枯燥的時間。  
  2.   1.製作Splash界面  
  3.   突出產品LOGO,產品名稱,產品主要特色;  
  4.   註明產品的版本信息;  
  5.   註明公司信息或者開發者信息;  
  6.   背景圖片,亦可以用背景顏色代替;  
  7.   2.除了等待還能做點什麼  
  8.   大多數的Splash界面都是會等待一定時間,然後切換到下一個界面;  
  9.   其實,在這段時間裏,可以對系統狀況進行檢測,比如網絡是否通,電源是否充足;  
  10.   或者,預先加載相關數據;  
  11.   爲了能讓啓動界面展現時間固定,需要計算執行以上預處理任務所花費的時間,那麼:啓動界面SLEEP的時間=固定時間-預處理任務時間;  
  12.   3.源碼示例</SPAN>  
  13.   <SPAN style="FONT-SIZE: 14px">AndroidMenifest.xml  
  14.   <activity android:icon="@drawable/app_icon"  
  15.                      android:screenOrientation="portrait"  
  16.                      android:name=".splashScreen"  
  17.                      android:theme="@android:style/Theme.NoTitleBar">  
  18.               <intent-filter>  
  19.                     <action android:name="android.intent.action.MAIN"/>  
  20.                    <category android:name="android.intent.category.LAUNCHER"/>  
  21.               </intent-filter>  
  22.           </activity>  
  23.   splashScreen.java  
  24.   package org.wordpress.android;  
  25.   import android.app.Activity;  
  26.   import android.content.Intent;  
  27.   import android.content.pm.PackageInfo;  
  28.   import android.content.pm.PackageManager;  
  29.   import android.content.pm.PackageManager.NameNotFoundException;  
  30.   import android.graphics.PixelFormat;  
  31.   import android.os.Bundle;  
  32.   import android.os.Handler;  
  33.   import android.view.WindowManager;  
  34.   import android.widget.TextView;  
  35.   
  36.   public class splashScreen extends Activity {  
  37.       /** 
  38.        * Called when the activity is first created. 
  39.        */  
  40.       @Override  
  41.       public void onCreate(Bundle icicle) {  
  42.           super.onCreate(icicle);  
  43.           getWindow().setFormat(PixelFormat.RGBA_8888);  
  44.           getWindow().addFlags(WindowManager.LayoutParams.FLAG_DITHER);  
  45.           setContentView(R.layout.splashscreen);  
  46.           //Display the current version number   
  47.           PackageManager pm = getPackageManager();  
  48.           try {  
  49.                PackageInfo pi = pm.getPackageInfo("org.wordpress.android"0);  
  50.                TextView versionNumber = (TextView) findViewById(R.id.versionNumber);  
  51.               versionNumber.setText("Version " + pi.versionName);  
  52.           } catch (NameNotFoundException e) {  
  53.               e.printStackTrace();  
  54.           }  
  55.           new Handler().postDelayed(new Runnable() {  
  56.               public void run() {  
  57.                     /* Create an Intent that will start the Main WordPress Activity. */  
  58.                     Intent mainIntent = new Intent(splashScreen.this, wpAndroid.class);  
  59.                     splashScreen.this.startActivity(mainIntent);  
  60.                   splashScreen.this.finish();  
  61.               }  
  62.           }, 2900); //2900 for release   
  63.       }  
  64.   }  
  65.   splashscreen.xml  
  66.   <!--  
  67.   android:gravity是對元素本身說的,元素本身的文本顯示在什麼地方靠着換個屬性設置,不過不設置默認是在左側的。  
  68.   android:layout_gravity是相對與它的父元素說的,說明元素顯示在父元素的什麼位置  
  69.   -->  
  70.   <LinearLayout android:id="@+id/LinearLayout01"  
  71.                 android:layout_width="fill_parent"  
  72.                 android:layout_height="fill_parent"  
  73.                   xmlns:android="http://schemas.android.com/apk/res/android"  
  74.                 android:gravity="center|center"  
  75.                 android:background="@drawable/home_gradient"  
  76.                 android:orientation="vertical">  
  77.       <!--  
  78.       android:scaleType是控制圖片如何resized/moved來匹對ImageView的size  
  79.       CENTER_INSIDE / centerInside  將圖片的內容完整居中顯示,通過按比例縮小或原來的size使得圖片長/寬等於或小於View的長/寬  
  80.       -->  
  81.       <ImageView android:layout_marginTop="-60dip"  
  82.                  android:paddingLeft="20dip"  
  83.                  android:paddingRight="20dip"  
  84.                  android:scaleType="centerInside"  
  85.                  android:layout_width="wrap_content"  
  86.                  android:layout_height="wrap_content"  
  87.                  android:id="@+id/wordpress_logo"  
  88.                    android:src="@drawable/wordpress_home">  
  89.       </ImageView>  
  90.       <!--  
  91.       android:typeface 字體風格  
  92.       -->  
  93.       <TextView android:text="@+id/TextView01"  
  94.                 android:layout_width="wrap_content"  
  95.                 android:layout_height="wrap_content"  
  96.                 android:layout_marginTop="20dip"  
  97.                 android:typeface="serif"  
  98.                 android:shadowDx="0"  
  99.                 android:shadowDy="2"  
  100.                 android:shadowRadius="1"  
  101.                 android:shadowColor="#FFFFFF"  
  102.                 android:textColor="#444444"  
  103.                 android:textSize="20dip"  
  104.                 android:id="@+id/versionNumber"  
  105.                 android:gravity="bottom">  
  106.       </TextView>  
  107.   </LinearLayout></SPAN>  
<span style="font-size:18px;">每個Android應用啓動之後都會出現一個Splash啓動界面,顯示產品的LOGO、公司的LOGO或者開發者信息。如果應用程序啓動時間比較長,那麼啓動界面就是一個很好的東西,可以讓用戶耐心等待這段枯燥的時間。
  1.製作Splash界面
  突出產品LOGO,產品名稱,產品主要特色;
  註明產品的版本信息;
  註明公司信息或者開發者信息;
  背景圖片,亦可以用背景顏色代替;
  2.除了等待還能做點什麼
  大多數的Splash界面都是會等待一定時間,然後切換到下一個界面;
  其實,在這段時間裏,可以對系統狀況進行檢測,比如網絡是否通,電源是否充足;
  或者,預先加載相關數據;
  爲了能讓啓動界面展現時間固定,需要計算執行以上預處理任務所花費的時間,那麼:啓動界面SLEEP的時間=固定時間-預處理任務時間;
  3.源碼示例</span>
  <span style="font-size:14px;">AndroidMenifest.xml
  <activity android:icon="@drawable/app_icon"
                     android:screenOrientation="portrait"
                     android:name=".splashScreen"
                     android:theme="@android:style/Theme.NoTitleBar">
              <intent-filter>
                    <action android:name="android.intent.action.MAIN"/>
                   <category android:name="android.intent.category.LAUNCHER"/>
              </intent-filter>
          </activity>
  splashScreen.java
  package org.wordpress.android;
  import android.app.Activity;
  import android.content.Intent;
  import android.content.pm.PackageInfo;
  import android.content.pm.PackageManager;
  import android.content.pm.PackageManager.NameNotFoundException;
  import android.graphics.PixelFormat;
  import android.os.Bundle;
  import android.os.Handler;
  import android.view.WindowManager;
  import android.widget.TextView;

  public class splashScreen extends Activity {
      /**
       * Called when the activity is first created.
       */
      @Override
      public void onCreate(Bundle icicle) {
          super.onCreate(icicle);
          getWindow().setFormat(PixelFormat.RGBA_8888);
          getWindow().addFlags(WindowManager.LayoutParams.FLAG_DITHER);
          setContentView(R.layout.splashscreen);
          //Display the current version number
          PackageManager pm = getPackageManager();
          try {
               PackageInfo pi = pm.getPackageInfo("org.wordpress.android", 0);
               TextView versionNumber = (TextView) findViewById(R.id.versionNumber);
              versionNumber.setText("Version " + pi.versionName);
          } catch (NameNotFoundException e) {
              e.printStackTrace();
          }
          new Handler().postDelayed(new Runnable() {
              public void run() {
                    /* Create an Intent that will start the Main WordPress Activity. */
                    Intent mainIntent = new Intent(splashScreen.this, wpAndroid.class);
                    splashScreen.this.startActivity(mainIntent);
                  splashScreen.this.finish();
              }
          }, 2900); //2900 for release
      }
  }
  splashscreen.xml
  <!--
  android:gravity是對元素本身說的,元素本身的文本顯示在什麼地方靠着換個屬性設置,不過不設置默認是在左側的。
  android:layout_gravity是相對與它的父元素說的,說明元素顯示在父元素的什麼位置
  -->
  <LinearLayout android:id="@+id/LinearLayout01"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                  xmlns:android="http://schemas.android.com/apk/res/android"
                android:gravity="center|center"
                android:background="@drawable/home_gradient"
                android:orientation="vertical">
      <!--
      android:scaleType是控制圖片如何resized/moved來匹對ImageView的size
      CENTER_INSIDE / centerInside  將圖片的內容完整居中顯示,通過按比例縮小或原來的size使得圖片長/寬等於或小於View的長/寬
      -->
      <ImageView android:layout_marginTop="-60dip"
                 android:paddingLeft="20dip"
                 android:paddingRight="20dip"
                 android:scaleType="centerInside"
                 android:layout_width="wrap_content"
                 android:layout_height="wrap_content"
                 android:id="@+id/wordpress_logo"
                   android:src="@drawable/wordpress_home">
      </ImageView>
      <!--
      android:typeface 字體風格
      -->
      <TextView android:text="@+id/TextView01"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="20dip"
                android:typeface="serif"
                android:shadowDx="0"
                android:shadowDy="2"
                android:shadowRadius="1"
                android:shadowColor="#FFFFFF"
                android:textColor="#444444"
                android:textSize="20dip"
                android:id="@+id/versionNumber"
                android:gravity="bottom">
      </TextView>
  </LinearLayout></span>
2.用動畫的方式實現

網址:http://smallmaple.iteye.com/blog/1255120

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章