2011-05-03 43 views

回答

18

如果您的意思是預加載器映像有閃屏,請參考以下代碼;

爲PhoneGap的:

public class MyDefaultActivity extends Activity { 

    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     super.setIntegerProperty("splashscreen", R.drawable.splash); // Displays the splash screen for android 
     super.loadUrl("file:///android_asset/www/index.html",3000); // Second parameter is duration for delay of splash screen 
    } 
} 

對於Android原生應用:

public class MySplashScreen extends Activity { 
    private CountDownTimer lTimer; 

    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     requestWindowFeature(Window.FEATURE_NO_TITLE); 
     setContentView(R.layout.splashscreen); // Contains only an LinearLayout with backround as image drawable 

     lTimer = new CountDownTimer(5000, 1000) { 
      public void onFinish() { 
       closeScreen(); 
      } 
      @Override 
      public void onTick(long millisUntilFinished) { 
       // TODO Auto-generated method stub 
      } 
     }.start(); 
    } 

    private void closeScreen() { 
     Intent lIntent = new Intent(); 
     lIntent.setClass(this, MyLauncherActivity.class); 
     startActivity(lIntent); 
     finish(); 
    } 
} 

確保一個名爲splash.png文件存在爲res/drawable-hdpi/splash.png(RGBA)。

+0

喜@ Vinayak.B,但之前的WebView完全加載我想說明我的公司徽標圖像第一..我在這裏寫了一個問題:http://stackoverflow.com/questions/16701179/how-to-change-background-image-on-android-progress-dialog我真的需要你的建議,謝謝 :) – bungdito 2013-05-22 20:50:15

4

您可以創建AsyncTask實現來顯示圖像/進度指示器,同時在後臺線程中加載應用程序的數據。

  1. 在異步任務的onPreExecute 方法告訴你所選擇的預加載 (圖像/ ProgressDialog /等)在doInBackground方法,你 開始在onPostExecute方法加載必要的數據, 和
  2. 你 刪除/隱藏你的preloader,所以 活動的預期佈局將顯示 顯示。
0

如果通過預加載圖像您指的是大圖像的低分辨率版本,您可以使用VewSwitcher帶有兩個ImageViews:一個圖像視圖包含預加載圖像,而其他包含完整的圖像(而它被加載)。最初,您可以使預加載的圖像可見,但是當大Bitmap完成加載時,只需使用switcher.showNext()即可顯示完整圖像。

有關ViewSwitcher(例子中做類似的東西)的一些進一步閱讀:我想問一下,如果我有針對Android的WebView應用程序代碼here

相關問題