首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >android中的Splashscreen无法正常工作

android中的Splashscreen无法正常工作
EN

Stack Overflow用户
提问于 2012-06-10 17:10:13
回答 3查看 513关注 0票数 0

我正在使用android应用程序的闪屏代码,它的代码发布在堆栈溢出上。我无法得到输出。下面是代码。

代码语言:javascript
运行
复制
package com.splash;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
public class SplashScreen extends Activity {

        private static final int SPLASH_DISPLAY_TIME = 3000;

        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.splash);

            new Handler().postDelayed(new Runnable() {

                public void run() {

                    Intent mainIntent = new Intent(Splashscreen.this,
                            MainActivity.class);
                    Splashscreen.this.startActivity(mainIntent);

                    Splashscreen.this.finish();
                    overridePendingTransition(R.anim.mainfadein,
                            R.anim.splashfadeout);
                }
            }, SPLASH_DISPLAY_TIME);
        }
    }
}

下面是splash.xml文件;

代码语言:javascript
运行
复制
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:src="@drawable/splash" />
</LinearLayout>

请告诉我怎么解决。我还为闪屏图像提供了fadein和fadeout xml文件。

EN

回答 3

Stack Overflow用户

发布于 2012-06-10 17:12:18

在您的代码中public class SplashScreen extends Activity {两次..

让它变得单一。

代码语言:javascript
运行
复制
package com.splash;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
public class SplashScreen extends Activity {

        private static final int SPLASH_DISPLAY_TIME = 3000;

        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.splash);

            new Handler().postDelayed(new Runnable() {

                public void run() {

                    Intent mainIntent = new Intent(Splashscreen.this,
                            MainActivity.class);
                    Splashscreen.this.startActivity(mainIntent);

                    Splashscreen.this.finish();
                    overridePendingTransition(R.anim.mainfadein,
                            R.anim.splashfadeout);
                }
            }, SPLASH_DISPLAY_TIME);
        }
    }
票数 0
EN

Stack Overflow用户

发布于 2012-06-10 18:41:17

确保在AndroidManifest.xml中添加了MainActivity。此外,发布来自logcat的异常堆栈跟踪也会有很大帮助。

票数 0
EN

Stack Overflow用户

发布于 2013-02-19 00:55:08

最有可能的情况是,您没有“MainActivity”类。检查它的名称是否正确。并确保它在正确的包中并添加到清单中。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/10967537

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档