2011-06-27 137 views
9

我想在應用程序啓動之前顯示徽標幾秒鐘,並且菜單可見。我也想在消失時使用一些。我應該創建一個新的活動嗎?我可以在佈局中設置它嗎?在應用程序啓動時顯示徽標幾秒鐘

+0

這可能會幫助你:http://www.barebonescoder.com/2010/04/a-simple-android-splash-screen/ –

+0

像一個閃屏? [Here](http://www.droidnova.com/how-to-create-a-splash-screen,561.html)就是一個例子。 –

+0

還檢查出http://www.gadgetsaint.com/android/create-video-splash-screen-android/ – ASP

回答

15

爲啓動屏幕定義一個佈局,其中將包含您的徽標,然後將此代碼添加到您的a ctivity:

public void onCreate(Bundle savedInstanceState){ 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.splash); 
    //display the logo during 5 seconds, 
    new CountDownTimer(5000,1000){ 
     @Override 
     public void onTick(long millisUntilFinished){} 

     @Override 
     public void onFinish(){ 
       //set the new Content of your activity 
       YourActivity.this.setContentView(R.layout.main); 
     } 
    }.start(); 
} 
+0

+,不知道CountDownTimer好戲 –

2

您可以使用獲取setVisibility(Visibility.GONE)的圖像視圖;或者某種程度上,或者你可以編寫一段時間結束後彈出並退出的活動。那是你的個人喜好...

0

爲什麼?用戶不喜歡等待。但是,如果你需要等待,因爲你加載一些數據,您可以:

public void onCreate(Bundle savedInstanceState){ 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.splash); 

    /* Do some work in a new thread, calling setContentView at the end with your view */ 
} 
0
package com.karan.android.video; 

import android.app.Activity; 
import android.content.Intent; 
import android.os.Bundle; 

public class splash extends Activity 
{ 

    @Override 
    public void onCreate(Bundle savedInstanceState) 
    { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.splash); 
     Thread splashThread = new Thread() 
     { 
     @Override 
     public void run() 
     { 
      try { 
       int waited = 0; 
       while (waited < 3000) 
       { 
        sleep(100); 
        waited += 100; 
       } 
      } catch (InterruptedException e) 
      { 
       // do nothing 
      } finally 
      { 
       finish(); 
       Intent i = new Intent(splash.this,video.class); 
       startActivity(i); 
      } 
     } 
     }; 
     splashThread.start(); 
    } 
} 

Xml file: 

<?xml version="1.0" encoding="utf-8"?> 
<FrameLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"> 

    <ImageView   
     android:src="@drawable/buff"  
     android:id="@+id/ImageView01" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content"> 
     </ImageView> 

    <TextView 
    android:textSize="40dp" 
    android:textColor="#CCFF00"  
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_gravity="center" 
    android:text="Buffering..." 
    /> 


</FrameLayout> 
0

延遲執行可以simplier方式實現:

new Handler().postDelayed(new Runnable() { 
    // ... Hide splash image and show the real UI 
}, 3000) 

而且Android標準android.widget.ViewSwitcher類是這種東西非常有用的。

相關問題