黑屏之前的Andr​​oid闪屏 [英] Android Splash Screen before black screen

查看:97
本文介绍了黑屏之前的Andr​​oid闪屏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想显示启动画面,而一切都初始化在OnCreate()方法,但我需要画的东西在屏幕上也初始化组件,因此有一个黑色的屏幕,当我启动应用程序,后的onCreate()方法完成则仅是绘制的第一个屏幕。而不必黑屏,我想一个启动画面。

I would like to display a splash screen while everything is initializing in the onCreate() method, yet components that I need to draw things to the screen are also initializing, therefore there's a black screen when I start the app and after the onCreate() method has completed then only is the first screen drawn. Instead of having the black screen I'd like a splash screen.

下面是我的code。在onCreate方法:

Here's my code in the onCreate method:

@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        // Acquire a wakeLock to prevent the phone from sleeping
        PowerManager powerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);
        wakeLock = powerManager.newWakeLock(PowerManager.FULL_WAKE_LOCK, "GLGame");

        // Setup all the Game Engine components 
        gameEngineLog = new WSLog("WSGameEngine");
        gameEngineLog.setLogType(this.gameEngineLogType);
        gameLog = new WSLog(this.gameLogTAG);
        gameLog.setLogType(this.gameLogType);
        io = new FileIO(this, getAssets());
        audio = new Audio(this);
        wsScreen = new WSScreen(this, this.screenResizeType, this.customTopYGap, this.customLeftXGap, this.gameScreenWidth, this.gameScreenHeight);
        graphics = new Graphics(this, wsScreen.getGameScreen(), wsScreen.getGameScreenextended());
        renderView = new RenderView(this, wsScreen.getGameScreen(), wsScreen.getGameScreenextended(), FPS, maxFrameskippes);
        input = new Input(this, renderView, logGameEngineInputLog);
        setContentView(renderView);

        if(useOfAnalytics == true) {
            getGameEngineLog().w(classTAG, "Analytics has been enabled");
            analytics = new Analytics(this);
        }

        // Check that the developer has initialized the assets
        if(this.assets == null) {
            this.gameEngineLog.w(classTAG, "The assets for the game haven't been defined!");
        }

    }

我应该

如何实现闪屏,避免黑屏的开头?

How should I implement a splash screen, to avoid the black screen at the beginning?

推荐答案

这个闪屏创建一个XML布局和设置您的super.onCreate为内容视图右后():

Create a XML layout for this splash screen and set it as content view right after your super.onCreate():

super.onCreate(savedInstanceState);
setContentView (R.layout.splash_screen);

这应该是足够了。这将显示该开机画面,直到你的setContentView(的RenderView)被调用。

That should be enough. It would display this splash screen until your setContentView(renderView) is called.

这篇关于黑屏之前的Andr​​oid闪屏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆