Android Splash Screen坏了

时间:2013-03-12 22:52:27

标签: android splash-screen

我用这个youtube video turtorial在这里做了一个启动画面〜> http://www.youtube.com/watch?v=IHg_0HJ5iQo

我保存了我的文件,并确保他们现在在那里当我将它发送到我的设备时,启动画面没有显示..我不知道为什么。

继承我的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>

继承我的manafest文件

<?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>

1 个答案:

答案 0 :(得分:0)

所以在聊天谈话之后,我发现你的启动画面没有显示的原因是因为你没有对splash.xml布局文件做任何事情。如果您没有对您的初始布局进行充气或将其设置为内容视图,那么您将永远不会看到它。

有几种方法可以做到这一点,但这是我要采取的方法:

  • 创建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>

请注意,这不是最好的方法,但它应该至少让你的闪屏显示并让你知道你需要去的方向。