启动画面布局没有任何影响

时间:2013-03-28 15:26:03

标签: android layout splash-screen

我的splashScreen有问题,这是启动活动,一切正常,但布局没有设置...

如果有人知道为什么?

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>

我的启动画面必须只显示一个图像和一个progressBar ...所有数据加载成功但没有布局只有带有actionBar的白色屏幕:(

由于

1 个答案:

答案 0 :(得分:0)

run方法中的代码几乎立即执行,这就是您无法看到SplashScreen的原因。你应该使用:

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