zoukankan      html  css  js  c++  java
  • android 启动界面

      很多应用都会有一个启动界面。启动画面,展示自己的LOGO、本版信息等,欢迎画面慢慢隐现,然后慢慢消隐。
      实现这种效果的方法有两种:

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

      使用两个Activity

    import android.app.Activity;
    import android.content.Intent;
    import android.os.Bundle;
    import android.os.Handler;
    import android.view.Window;
    //SplashActivity    注意要在AndroidManifest.xml配置为启动页
    public class SplashActivity extends Activity {
    	public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            requestWindowFeature(Window.FEATURE_NO_TITLE);// 去掉标题栏
            setContentView(R.layout.splash);
            MyApplication.getInstance().addActivity(this);
            Handler x = new Handler();
            x.postDelayed(new splashhandler(), 2000); //设置延迟执行时间
        }
    	
        class splashhandler implements Runnable{
            public void run() {
                startActivity(new Intent(getApplication(),LoginActivity.class));  //启动主Activity
                SplashActivity.this.finish();  // 关闭启动页Activity
            }
        }
    }

       启动页布局

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout
      xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_height="fill_parent" 
      android:layout_width="fill_parent" 
      android:orientation="vertical" 
      android:background="#ff0099d6">
    	<ImageView 
    	    android:layout_height="fill_parent" 
    	    android:layout_width="fill_parent" 
    	    android:scaleType="fitCenter" 
    	    android:src="@drawable/qidongye">
    	</ImageView>
    </LinearLayout>
    

       使用一个Activity

    public class WebGameActivity extends Activity { 
      private WebView webView;   
      private Handler mHandler = new Handler(); 
      private static final String TAG = "WebGameActivity";   
      //菜单 
      private static final int MENU_RELOAD = Menu.FIRST; 
      private static final int MENU_HELP = Menu.FIRST + 1; 
      private static final int MENU_ABOUT = Menu.FIRST + 2; 
      private static final int MENU_CLOSE = Menu.FIRST + 3;   
      private int staus  = 0;  
      private static final int  STOPSPLASH = 0; 
      //延迟时间 
      private static final long SPLASHTIME = 1000; 
      private LinearLayout splash; 
      private TextView tv; 
      private Animation myAnimation_Alpha; 
      private Animation animatinoGone ; 
      
      private Handler splashHandler = new Handler() { 
        public void handleMessage(Message msg) { 
             switch (msg.what) { 
             case STOPSPLASH: 
                  if( staus == 1 ){                
                    splash.startAnimation(animatinoGone); 
                    splash.setVisibility(View.GONE); 
                    break; 
                  } 
                  sendEmptyMessageDelayed(STOPSPLASH, SPLASHTIME); 
             } 
             super.handleMessage(msg); 
        } 
    }; 
      
      @Override 
      protected void onCreate(Bundle savedInstanceState) { 
        super.onCreate(savedInstanceState); 
        getWindow().requestFeature(Window.FEATURE_PROGRESS); //去标题栏 
        setContentView(R.layout.main);    
        animatinoGone = AnimationUtils.loadAnimation(this,R.anim.alpha_gone); //动画效果 
        myAnimation_Alpha = AnimationUtils.loadAnimation(this,R.anim.alpha_action); //动画效果 
        
        splash = (LinearLayout) findViewById(R.id.splashscreen); 
        tv = (TextView) findViewById(R.id.info); 
        tv.setText("正在建立数据连接"); 
        splash.startAnimation(myAnimation_Alpha); 
        
        Message msg = new Message(); 
        msg.what = STOPSPLASH; 
        splashHandler.sendMessageDelayed(msg, SPLASHTIME); 
    }
    

       布局文件

    <?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是程序的主界面显示部分。

  • 相关阅读:
    分享几个原生javascript面向对象设计小游戏
    原生javascript模仿win8等待进度条。
    微信公众平台入门开发教程.Net(C#)框架
    AsyncDelegate
    Lock
    BackgroundWorker
    Thread
    深拷贝-浅拷贝
    WindowsService
    事件本质
  • 原文地址:https://www.cnblogs.com/flowers-yang/p/3409611.html
Copyright © 2011-2022 走看看