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

问题描述

我和我的 SplashScreenActivity ,当我开始我的手机上我的应用程序它显示一个白色的屏幕约0.5秒的问题。在 MainActitivy 扩展 FragmentActivity ,并在 AndroidManifest 我宣布 SplashScreenActivity 作为发射和肖像模式 screenOrientation

的code:

 公共类SplashScreenActivity延伸活动{@覆盖
保护无效的onCreate(捆绑savedInstanceState){
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    的setContentView(R.layout.splashscreen);
    randomSplash();    螺纹闪屏=新的Thread(){        公共无效的run(){
            尝试{
                视频下载(1000);
                意图mainScreen =新意图(com.rm.jkrm.MAINACTIVITY);
                startActivity(mainScreen);
            }赶上(InterruptedException的E){            } {最后
                完();
            }
        }
    };
    splashscreen.start();
}私人无效randomSplash(){
    随机随机=新的随机();
    INT I = random.nextInt(4);    LN的LinearLayout =(的LinearLayout)findViewById(R.id.splashscreen);    开关(ⅰ){
    情况1:
        ln.setBackgroundResource(R.drawable.splash1);
        打破;
    案例2:
        ln.setBackgroundResource(R.drawable.splash2);
        打破;
    案例3:
        ln.setBackgroundResource(R.drawable.splash3);
        打破;
    默认:
        ln.setBackgroundResource(R.drawable.splash0);
        打破;
    }
}
}

XML:

 <?XML版本=1.0编码=UTF-8&GT?;
 < LinearLayout中的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
 机器人:ID =@ + ID /闪屏
 机器人:layout_width =match_parent
 机器人:layout_height =match_parent
 机器人:方向=垂直>
< / LinearLayout中>


解决方案

您需要运行在此AsyncTask的两个动作:

 的setContentView(R.layout.splashscreen);
randomSplash();

的setContentView 在doInBackground-方法和运行 randomSplash 的postExecute方法。

I have an issue with my SplashScreenActivity, when I start my application on my phone it shows a white screen for about 0,5 seconds. The MainActitivy extends FragmentActivity and in the AndroidManifest I declare the SplashScreenActivity as launcher and portrait mode as screenOrientation.

The code:

public class SplashScreenActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.splashscreen);
    randomSplash();

    Thread splashscreen = new Thread() {

        public void run() {
            try {
                Thread.sleep(1000);
                Intent mainScreen = new Intent("com.rm.jkrm.MAINACTIVITY");
                startActivity(mainScreen);
            } catch (InterruptedException e) {

            } finally {
                finish();
            }
        }
    };
    splashscreen.start();
}

private void randomSplash(){
    Random random = new Random();
    int i = random.nextInt(4);

    LinearLayout ln = (LinearLayout) findViewById(R.id.splashscreen);

    switch(i){
    case 1:
        ln.setBackgroundResource(R.drawable.splash1);
        break;
    case 2:
        ln.setBackgroundResource(R.drawable.splash2);
        break;
    case 3:
        ln.setBackgroundResource(R.drawable.splash3);
        break;
    default:
        ln.setBackgroundResource(R.drawable.splash0);
        break;
    }
}
}

XML:

 <?xml version="1.0" encoding="utf-8"?>
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 android:id="@+id/splashscreen"
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 android:orientation="vertical">
</LinearLayout>
解决方案

You need to run this two actions in an AsyncTask:

setContentView(R.layout.splashscreen);
randomSplash();

put the setContentView in the doInBackground-method and in the postExecute method you run randomSplash.

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

08-31 03:55