2013-03-28 63 views
0

我有一個問題,我閃屏,這是啓動的活動,所有工作正常,但佈局不設置...閃屏佈局don'nt有什麼影響

如果有人知道爲什麼嗎?

Splashscreen.java 




    import org.w3c.dom.Document; 
    import org.w3c.dom.Element; 
    import org.w3c.dom.NodeList; 

    import android.app.Activity; 
    import android.content.Intent; 
    import android.content.SharedPreferences; 
    import android.os.Bundle; 
    import android.os.Handler; 
    import android.os.StrictMode; 
    import android.view.LayoutInflater; 
    import android.view.View; 
    import android.view.ViewGroup; 



    public class SplashScreen extends Activity { 



     // =========================================================== 

     // Fields 

     // =========================================================== 


     public final static String PREFS_NAME = "Contest"; 
     public final static String PREFS_NAME_IMAGE = "Image"; 
     private final int SPLASH_DISPLAY_LENGHT = 10000; 
     public String[][] imageID = null; 


     @Override 
     public void onCreate(Bundle icicle) { 
       super.onCreate(icicle); 
       setContentView(R.layout.splashscreen); 
       getActionBar().hide(); 
       //Only for safe mode 
       StrictMode.ThreadPolicy policy = new StrictMode. 
       ThreadPolicy.Builder().permitAll().build(); 
       StrictMode.setThreadPolicy(policy); 

       /**********Fetch user info (if exist)************/ 
       String id = User.getUserId(getApplicationContext()); 
         /*****Else create New User********/ 
       if (id == "") 
       { 
        System.out.println("Create New User..."); 
        UserRegistration.CreateUser(getApplicationContext()); 
       } 
       /***************** USER END ************************/ 



       /* New Handler to start the Menu-Activity 

       * and close this Splash-Screen after some seconds.*/ 

       new Handler().post(new Runnable(){ 

         @Override 

         public void run() { 
          setContentView(R.layout.splashscreen); 
          String id = User.getUserId(getApplicationContext()); 
          String pass = User.getUserPass(getApplicationContext()); 
          String URL = "URL; 
          System.out.println(URL); 
          String xmlBoutique = new XMLfunctionsBack().doInBackground("URL; 
          String xmlRestaurant = new XMLfunctionsBack().doInBackground("URL); 
          String xmlNightlife = new XMLfunctionsBack().doInBackground("URL); 
          String xmlLoisir = new XMLfunctionsBack().doInBackground("URL); 
          String xmlEvenement = new XMLfunctionsBack().doInBackground("URL); 

          //Clean previous Data// 
          SharedPreferences sharedPrefClean= getSharedPreferences(PREFS_NAME, 0); 
          SharedPreferences.Editor editorClean= sharedPrefClean.edit(); 
          editorClean.putString("xmlBoutique", ""); 
          editorClean.putString("xmlRestaurant", ""); 
          editorClean.putString("xmlNightlife", ""); 
          editorClean.putString("xmlLoisir", ""); 
          editorClean.putString("xmlEvenement", ""); 
          editorClean.commit(); 

          /****************Fetch Image ID for future Background Loading *****************/ 
          SharedPreferences sharedPrefImage= getSharedPreferences(PREFS_NAME_IMAGE, 0); 
          SharedPreferences.Editor editorImage= sharedPrefImage.edit(); 
          for (int x = 0; x <= 5; x++) {  
           Document doc = XMLfunctions.XMLfromString(xmlBoutique); 
           NodeList nodes = doc.getElementsByTagName("contest"); 
           for (int i = 0; i < nodes.getLength(); i++) {       
            Element e = (Element)nodes.item(i); 
            String sX = String.valueOf(x) ; 
            String sI = String.valueOf(i) ; 
            String entry = sX+=sI; 
            editorImage.putString(entry, XMLfunctions.getValue(e, "image")); 
            editorImage.commit(); 
           } 
          } 

          SharedPreferences sharedPref= getSharedPreferences(PREFS_NAME, 0); 
          SharedPreferences.Editor editor= sharedPref.edit(); 
          editor.putString("xmlBoutique", xmlBoutique); 
          editor.putString("xmlRestaurant", xmlRestaurant); 
          editor.putString("xmlNightlife", xmlNightlife); 
          editor.putString("xmlLoisir", xmlLoisir); 
          editor.putString("xmlEvenement", xmlEvenement); 
          editor.commit(); 
           /* Create an Intent that will start the Menu-Activity.*/ 

           Intent intent = new Intent(getBaseContext() ,MainActivity.class); 
           intent.putExtra("loadingFinish", "SUCCESS"); 
           startActivity(intent); 
           //AsyncTask<Void, Void, Void> background = new BackgroundTask().execute(); 
           SplashScreen.this.finish(); 
         } 

       }); 

     } 

     } 

SplashScreen.xml

<?xml version="1.0" encoding="utf-8"?> 
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="@drawable/splash_screen" 
    android:orientation="vertical"> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:gravity="bottom" 
     android:paddingBottom="@dimen/cinquantedp" > 

     <ProgressBar 
      android:id="@+id/progressBar1" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" /> 

     <LinearLayout 
      android:layout_width="wrap_content" 
      android:layout_height="match_parent" 
      android:gravity="bottom" 
      android:paddingLeft="@dimen/padding_large" > 

      <TextView 
       android:id="@+id/textView1" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="Chargement des concours" 
       android:textAppearance="?android:attr/textAppearanceMedium" /> 

     </LinearLayout> 

    </LinearLayout> 

</LinearLayout> 

清單

<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
    package="xxx.android" 
    android:versionCode="1" 
    android:versionName="1.0" > 
    <uses-permission android:name="android.permission.INTERNET"/> 
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> 
    <uses-sdk 
     android:minSdkVersion="14" 
     android:targetSdkVersion="15" /> 

    <application 
     android:icon="@drawable/ic_launcher" 
     android:label="@string/app_name" 
     android:theme="@style/AppTheme" > 
     <activity 
      android:name="xxx.android.MainActivity" 
      android:label="@string/title_activity_main" > 
     </activity> 
     <activity 
      android:name="xxx.android.Participate" 
      android:label="@string/app_name" > 
     </activity> 
     <activity 
      android:name="xxx.android.SplashScreen" 
      android:label="@string/app_name" > 
      <intent-filter> 
       <action android:name="android.intent.action.MAIN" /> 
       <category android:name="android.intent.category.LAUNCHER" /> 
      </intent-filter> 
     </activity> 
     <activity 
      android:name="xxx.android.ShowContest" 
      android:label="@string/app_name" > 
     </activity> 
    </application> 

</manifest> 

我的啓動畫面必須只顯示一個圖像和一個進度條......所有數據加載成功,但沒有佈局只是白色屏幕,動作條:(

謝謝

+0

你爲什麼要在Handler中調用setContentView(R.layout.splashscreen);' –

+0

只是爲了嘗試,如果有任何影響,但沒有:( –

回答

0

run方法中的代碼幾乎立即執行,這就是爲什麼你不能看到SplashScreen。你應該使用:

mHandler.postDelayed(new Runnable(){...}, SPLASH_DISPLAY_LENGHT); 
+0

不明白.. –