2011-12-11 32 views
1

我創建了一個初始屏幕,但是當我啓動我的應用程序時,初始屏幕不顯示,只是一個黑色屏幕。不過,在啓動畫面的計時器結束後,我的菜單出現了。在我的splashscreen.xml的圖形佈局中,閃屏圖像顯示。但是運行時,它不會。一切都只是我的啓動畫面正常...android eclipse初始屏幕圖像不顯示

代碼myMain.java:

package com.immrroj.firstapp; 

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

public class myMain extends Activity 
{ 

@Override 
protected void onCreate(Bundle savedInstanceState) 
{ 
    // TODO Auto-generated method stub 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.splashscreen); 
    Thread splashtimer = new Thread() 
    { 
     @Override 
     public void run() 
     { 
      try 
      { 
       int timer = 0; 
       while (timer < 5000) 
       { 
        sleep(100); 
        timer = timer + 100; 
       } 
       startActivity(new Intent("com.immrroj.firstapp.CLEARSCREEN")); 
      } catch (InterruptedException e) 
      { 
       // TODO Auto-generated catch block 
       e.printStackTrace(); 
      } 

      finally 
      { 
       finish(); 
      } 
     } 
    }; 
    splashtimer.run(); 
} 

@Override 
protected void onDestroy() 
{ 
    // TODO Auto-generated method stub 
    super.onDestroy(); 
} 

@Override 
protected void onResume() 
{ 
    // TODO Auto-generated method stub 
    super.onResume(); 
} 

@Override 
protected void onStart() 
{ 
    // TODO Auto-generated method stub 
    super.onStart(); 
} 

@Override 
protected void onStop() 
{ 
    // TODO Auto-generated method stub 
    super.onStop(); 
} 

} 

代碼myMenu.java

package com.immrroj.firstapp; 

import android.app.Activity; 
import android.os.Bundle; 

public class myMenu extends Activity 
{ 

@Override 
protected void onCreate(Bundle savedInstanceState) 
{ 
    // TODO Auto-generated method stub 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main); 
} 

} 

代碼爲我的main.xml

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

<Button 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="PRESS ME!!" 
    android:textSize="19dp" 
    android:textStyle="bold" 
    android:width="200dp" android:layout_gravity="right"/> 

<Button 
    android:id="@+id/button1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="PRESS ME TOO!" 
    android:gravity="center" 
    android:textSize="19dp" 
    android:textStyle="bold" android:width="200dp" android:layout_gravity="right"/> 

</LinearLayout> 

我的splashscreen.xml代碼....圖像androidsplash沒有顯示

我的Android清單
<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:orientation="vertical" > 

<ImageView 
    android:src="@drawable/androidsplash" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    /> 

</LinearLayout> 

代碼:

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

<uses-sdk android:minSdkVersion="10" /> 

<application 
    android:icon="@drawable/ic_launcher" 
    android:label="@string/app_name" > 
    <activity 
     android:label="@string/app_name" 
     android:name=".myMain" > 
     <intent-filter > 
      <action android:name="android.intent.action.MAIN" /> 
      <category android:name="android.intent.category.LAUNCHER" /> 
     </intent-filter> 
    </activity> 
    <activity 
     android:label="@string/app_name" 
     android:name=".myMenu" > 
     <intent-filter > 
      <action android:name="com.immrroj.firstapp.CLEARSCREEN" /> 
      <category android:name="android.intent.category.DEFAULT" /> 
     </intent-filter> 
    </activity> 
</application> 

</manifest> 

請help..although我可以繼續下去,那就真的竊聽我....

UPDATE: 好吧...我認爲它真的很難解決這個問題,但沒有手中的代碼...所以即時通訊發佈此鏈接,所以任何人都可以看到代碼和修補它...請幫助我...我wnat學習機器人,但我卡在這裏.. ..在這裏下載源代碼,這是安全的,我發誓:https://skydrive.live.com/redir.aspx?cid=79ecba5b079a1b4c&resid=79ECBA5B079A1B4C!293&parid=79ECBA5B079A1B4C!113&authkey=!AK8-cta_tThQUms

+0

你可以把帶有一些文本的'TextView'放到你的splash xml佈局中嗎?我的猜測是它的圖像沒有被顯示。 – inazaruk

+0

我先刪除了圖片,然後放了一個textview ...但是,在啓動屏幕加載過程中文本也沒有顯示.... TT –

回答

1

明白了。

下載你的.rar並給它看看。原來你的Thread出了問題。我不知道究竟是什麼,但它導致佈局不能正確加載(可能是因爲你讓它睡了100毫秒,然後醒來,檢查一個變量,並再次睡100毫秒)。

我改變你的線程用下面的代碼,現在它完美的作品在我的手機:

@Override 
    protected void onCreate(Bundle savedInstanceState) { 
     // TODO Auto-generated method stub 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.splashscreen); 

     Thread timer = new Thread() { 
      // Thread to show the splash screen, then launch the main screen 
      @Override 
      public void run() { 
       try { 
        sleep(2500); // set this to how long you want to wait before 
            // showing the main screen 
       } catch (InterruptedException e) { 
        e.printStackTrace(); 
       } finally { 
        Intent mainScreen = new Intent(
          "com.immrroj.firstapp.CLEARSCREEN"); 
        startActivity(mainScreen); 
       } 
      } 
     }; 
     timer.start(); 
    } 

您可以將其他所有onStart, onPause etc方法了,你不使用那些閃屏反正。

我在這裏上傳了編輯的代碼:Download

祝您的應用程序!

+0

awww ...它也不能正常工作.... –

+0

如果刪除定時器,以及所有的onStop等方法,只留下基本的'onCreate'和'setContentView',它的工作呢? 因爲它只是一個啓動畫面,所以你不需要其他'on ...'方法。 –

+0

仍然沒有工作.... –