2013-03-12 77 views
0

我犯了一個閃屏與此YouTube視頻turtorial這裏〜>http://www.youtube.com/watch?v=IHg_0HJ5iQoAndroid的閃屏碎

我救了我的文件,並確保他們現在在那裏當我把它發送到我的設備開機畫面顯示不出來..我不知道爲什麼。

我的繼承人activity_main.xml中的代碼

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:background="@drawable/back_background" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:paddingBottom="@dimen/activity_vertical_margin" 
    android:paddingLeft="@dimen/activity_horizontal_margin" 
    android:paddingRight="@dimen/activity_horizontal_margin" 
    android:paddingTop="@dimen/activity_vertical_margin" 
    tools:context=".MainActivity" > 

</RelativeLayout> 

這裏是我的splash.xml代碼

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


</LinearLayout> 

我的繼承人馬納費斯特文件

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
package="com.example.idoser" 
android:versionCode="1" 
android:versionName="1.0" > 

<uses-sdk 
    android:minSdkVersion="8" 
    android:targetSdkVersion="17" /> 

<application 
    android:allowBackup="true" 
    android:icon="@drawable/ic_launcher" 
    android:label="@string/app_name" 
    android:theme="@style/AppTheme" > 
    <activity 
     android:name="com.example.idoser.MainActivity" 
     android:label="@string/app_name" > 
     <intent-filter> 
      <action android:name="android.intent.action.MAIN" /> 

      <category android:name="android.intent.category.LAUNCHER" /> 
     </intent-filter> 
    </activity> 
</application> 

</manifest> 
+0

你可以發佈你的清單文件嗎? – MCeley 2013-03-12 22:53:33

+0

即時運行android 4.2.1和ok – 2013-03-12 22:54:41

+0

不管你運行的是哪個版本,你可以發佈你的清單文件嗎?我希望看到您的活動聲明,以確保您首先啓動適當的活動。 – MCeley 2013-03-12 22:55:36

回答

0

所以在聊天交談後,我看到你的啓動畫面沒有顯示的原因是因爲你沒有對做任何事情佈局文件。如果您沒有膨脹飛濺佈局或將其設置爲內容視圖,那麼您將永遠無法看到它。

有幾種方法可以做到這一點,但這個是我會採取的做法:

  • 創建SplashActivity
  • 製作SplashActivity你的發射活動。
  • 使用計時器開始您的主要活動。

SplashActivity.java

package com.example.idoser; 

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

public class SplashActivity extends Activity { 

    AsyncTask<Object, Object, Object> mTimerTask; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.splash); 
    } 

    @Override 
    protected void onResume() { 
     super.onResume(); 

     if(mTimerTask != null) { 
      mTimerTask.cancel(false); 
      mTimerTask = null; 
     } 

     mTimerTask = new AsyncTask<Object, Object, Object>() { 

      @Override 
      protected Object doInBackground(Object... params) { 
       try { 
        Thread.sleep(3000); /* 3 second splash screen */ 
       } catch(Exception e) { } 

       return null; 
      } 

      @Override 
      protected void onPostExecute(Object result) { 
       super.onPostExecute(result); 

       Intent intent = new Intent(SplashActivity.this, MainActivity.class); 
       startActivity(intent); 
       finish(); 
      } 
     }; 
    } 

    @Override 
    protected void onPause() { 
     super.onPause(); 

     if(mTimerTask != null) { 
      mTimerTask.cancel(false); 
      mTimerTask = null; 
     } 
    } 

} 

AndroidManifest.xml中

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
    package="com.example.idoser" 
    android:versionCode="1" 
    android:versionName="1.0" > 

    <uses-sdk 
     android:minSdkVersion="8" 
     android:targetSdkVersion="17" /> 

    <application 
     android:allowBackup="true" 
     android:icon="@drawable/ic_launcher" 
     android:label="@string/app_name" 
     android:theme="@style/AppTheme" > 
     <activity 
      android:name="com.example.idoser.SplashActivity" 
      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="com.example.idoser.MainActivity" 
      android:label="@string/app_name" > 
     </activity> 
    </application> 
</manifest> 

你要知道這是不是最好的方式做到這一點,但它至少應該讓你的閃屏顯示,並給你想到了你需要走的方向。

+0

我把這個放在什麼目錄裏? – 2013-03-13 00:01:29

+0

好了,現在我該怎麼做? http://stackoverflow.com/questions/15376970/android-eclipse-button-onclick-event – 2013-03-13 04:25:51

+0

這是一個單獨的問題,將作爲回答。如果這裏的答案滿足這個問題的需要,那麼一定要接受它,以便其他人可以從這裏的信息中受益。您可以通過點擊投票箭頭下方的複選標記來接受答案。 – MCeley 2013-03-13 12:08:23