我想用這個java和xml代碼實現一個啓動畫面。我從我的主要活動創建了一個單獨的java類,並將java代碼放在裏面。我在佈局文件中創建了一個xml佈局,並將xml代碼放入其中。不過,我的應用通常沒有啓動畫面。它從不顯示,但該應用程序沒有任何錯誤。 Eclipse也沒有顯示任何錯誤。這可能是什麼原因?先謝謝你。這是代碼。啓動畫面不會顯示
的Java:
package com.carouseldemo.main;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.view.Menu;
public class Splash extends Activity {
private final int SPLASH_DISPLAY_LENGHT = 1000;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.splash);
/* New Handler to start the Menu-Activity
* and close this Splash-Screen after some seconds.*/
new Handler().postDelayed(new Runnable(){
@Override
public void run() {
/* Create an Intent that will start the Menu-Activity. */
Intent mainIntent = new Intent(Splash.this,Menu.class);
Splash.this.startActivity(mainIntent);
Splash.this.finish();
}
}, SPLASH_DISPLAY_LENGHT);
}
}
XML:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageView android:id="@+id/splashscreen" android:layout_width="wrap_content"
android:layout_height="fill_parent" android:src="@drawable/cat"
android:layout_gravity="center"/>
<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content" android:text="Hello World, splash"/>
</LinearLayout>
清單:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.carouseldemo.main"
android:versionCode="1"
android:versionName="1.0"
>
<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="17" android:screenOrientation="portrait"/>
<application android:icon="@drawable/buttonone" android:label="@string/app_name">
<activity android:name=".MainActivity" android:label="@string/app_name" android:screenOrientation="portrait" android:configChanges="orientation|keyboardHidden" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
啓動畫面顯示時間爲1秒,您可以將它保持在4-5秒左右並再次檢查。 –
我把時間增加到了10秒。它顯示大約一秒鐘的黑屏並打開應用程序。 –
Manifest文件怎麼樣?你有沒有註冊啓動屏幕作爲啓動活動..你可以發佈你的manisfest文件嗎? –