2011-06-24 123 views
0

我有一个短暂的延迟启动画面,延迟后,它移动到splashscreen但我似乎无法覆盖过渡,我不明白为什么......虽然过渡确实工作在调试模式很奇怪Android转换不起作用

package com.example.android.bubblestrouble; 

import android.app.Activity; import android.content.Intent; import android.os.Bundle;

公共类队延伸活动{

@Override 
public void onCreate(Bundle savedInstanceState) 
{ 
    super.onCreate(savedInstanceState); 
    final int delay = 3000; 
    setContentView(R.layout.team); 
    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 < delay) 
       { 
        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(Team.this, SplashScreen.class)); 
      Team.this.finish(); 
      Team.this.overridePendingTransition(R.anim.fade, R.anim.hold); 
     } 
    } 
    }; 
    welcomeThread.start(); 
} 

}

回答

0

直溶液。在活动开始时立即显示您的飞溅图像,并用计时器替换所需的布局。像这样的东西(onCreate事件Team活动):

ImageView splashImage = new ImageView(this); 
splashImage.setImageBitmap(splashBitmap); // or drawable/resource - as you like 
setContentView(splashImage); 
Thread timerThread = new Thread() { 
    @Override 
    public void run() { 
     sleep(3000); 
     Team.runOnUiThread(new Runnable() { 
      @Override 
      public void run() { 
       setContentView(R.layout.team); 
      } 
     }); 
    } 
} 
timerThread.start(); 
+0

感谢,虽然这个应用程序,心不是最好的做法。主要问题是,我不明白为什么overridePendingTransition不起作用。我正尝试使用转换效果,这是实现这个的最佳方法 – Chris

+0

也许问题出在睡眠周期?尝试使用'睡眠(3000)'而不是增量 –