android几种欢迎界面的实现 .

来源:互联网 发布:python 集成安装包 编辑:程序博客网 时间:2024/06/05 01:13

1.用handler的postDelayed实现

转载自:http://www.eoeandroid.com/blog-535302-2331.html

[java] view plaincopyprint?
  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>  
2.用动画的方式实现

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

0 0
原创粉丝点击