【问题标题】:How to remove Activity layout flickers when switching from full screen activity to normal activity(with Action Bar)?从全屏活动切换到正常活动(使用操作栏)时如何消除活动布局闪烁?
【发布时间】:2015-08-17 03:01:48
【问题描述】:

我正在使用全屏大小的初始屏幕,没有操作栏布局,但是当我移动到登录活动时,这是具有操作栏的正常活动,我的布局不能顺利移动,它显示一些闪烁(上/下)。我不是克服它请帮助...

我正在使用 Intent 将动作从启动活动传递到登录活动

这是我的启动画面代码:

public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.splash);
        /* set time to splash out */
        final int welcomeScreenDisplay = 4000;
        /* create a thread to show splash up to splash time */
        Thread welcomeThread = new Thread() {
            int wait = 0;

            @Override
            public void run() {
                try {
                    super.run();
                    /*
                     * use while to get the splash time. Use sleep() to increase
                     * the wait variable for every 100L.
                     */
                    while (wait < welcomeScreenDisplay) {
                        sleep(100);
                        wait += 100;
                    }
                } catch (Exception e) {
                    System.out.println("EXc=" + e);
                } finally {
                    /*
                     * Called after splash times up. Do some action after splash
                     * times up. Here we moved to another main activity class
                     */
                    startActivity(new Intent(SplashActivity.this,
                            LoginActivity.class));
                    finish();
                }
            }
        };
        welcomeThread.start();
    }
}

【问题讨论】:

  • 你能把你的启动活动的代码贴出来
  • 我已经在这里发布了启动活动代码

标签: android layout screen splash-screen


【解决方案1】:

使用它来创建延迟

/** Duration of wait **/
    private final int SPLASH_DISPLAY_LENGTH = 1000;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle icicle) {
        super.onCreate(icicle);
        setContentView(R.layout.splashscreen);

        /* 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_LENGTH);
    }

【讨论】:

  • 感谢您的回复,但这对我没有帮助。您认为动画可能是解决此问题的一种方法
【解决方案2】:

身份启动您的活动
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);
                mainIntent.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
                Splash.this.startActivity(mainIntent);
                Splash.this.overridePendingTransition(0,0);
                Splash.this.finish();
            }
        }, SPLASH_DISPLAY_LENGTH);

【讨论】:

    【解决方案3】:

    它解决了你的问题。

        getWindow().addFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
        getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
    
        startActivity(new Intent(SplashActivity.this,LoginActivity.class));
    
        // for activity animation.
        //overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);
        finish();
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-03-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多