2011-06-27 22 views
9

Tôi muốn hiển thị biểu tượng trong vài giây trước khi bắt đầu ứng dụng và menu hiển thị. Tôi cũng muốn sử dụng một số khi nó biến mất. Tôi có nên tạo hoạt động mới không? Tôi có thể đặt nó trong bố cục không?Hiển thị biểu tượng trong vài giây khi bắt đầu ứng dụng

+0

điều này có thể giúp bạn: http://www.barebonescoder.com/2010/04/a-simple-android-splash-screen/ –

+0

Giống như màn hình giật gân? [Ở đây] (http://www.droidnova.com/how-to-create-a-splash-screen,561.html) là một ví dụ. –

+0

Ngoài ra, hãy xem http://www.gadgetsaint.com/android/create-video-splash-screen-android/ – ASP

Trả lời

15

xác định bố cục cho màn hình giật gân chứa biểu tượng của bạn và sau đó, thêm mã này vào 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

+, không biết về thủ thuật lừa đảo CountDownTimer –

2

Bạn có thể sử dụng chế độ xem hình ảnh được setVisibility (Visibility.GONE); hoặc một cái gì đó ở mức độ đó, hoặc bạn có thể viết một hoạt động mà chỉ bật lên và bỏ ra sau một thời gian kết thúc. Đó là sở thích cá nhân của bạn ...

0

Tại sao? Người dùng không thích chờ đợi. Tuy nhiên, nếu bạn cần phải chờ đợi vì bạn đang tải một số dữ liệu, bạn có thể:

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

thực hiện chậm có thể được thực hiện theo cách đơn giản hơn:

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

Ngoài ra android chuẩn android.widget.ViewSwitcher lớp là rất có ích cho các loại của sự vật.

Các vấn đề liên quan