2011-06-03 45 views
0

我相當新的android。我想在Android中將兩個圖像背對背(每一個持續一段時間)顯示爲閃屏。我能夠顯示單個圖像,但努力顯示其他圖像。如何在android中顯示多個圖像作爲啓動畫面?

public class SplashScreen extends Activity { 

    /** 
    * The thread to process splash screen events 
    */ 
    private Thread mSplashThread;  

    /** Called when the activity is first created. */ 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 

     // Splash screen view 
     setContentView(R.layout.splash); 

     final SplashScreen sPlashScreen = this; 

     // The thread to wait for splash screen events 
     mSplashThread = new Thread(){ 
      @Override 
      public void run(){ 
       try { 
         Thread.sleep(1000); 
       } 
       catch(InterruptedException ex){      
       } 

       finish(); 

       // Run next activity 
       Intent intent = new Intent(); 
       intent.setClass(sPlashScreen, MainActivity.class); 
       startActivity(intent); 
       stop();      
      } 
     }; 

     mSplashThread.start();   
    } 

有沒有一種方法可以替換ImageView中的圖像?

謝謝!

回答

2

First read the first about 5 pages of this.當onCreate運行時,活動尚不可見。所以你不能在onCreate中改變圖像。該活動在onStart運行之前不可見。您可以在onCreate中設置圖像,然後在onStart啓動一個睡眠1秒鐘的AsyncTask,然後加載第二張圖像,然後再睡一秒,然後啓動主屏幕。

0
public class SplashScreen extends Activity { 
private ImageView image; 
private Thread splashTread; 

private LinearLayout linear; 
@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.splash); 
    final Handler handler = new Handler() { 



    @Override 
    public void handleMessage(Message msg) { 
    super.handleMessage(msg); 
    linear = (LinearLayout) findViewById(R.id.splash_linear); 
    Drawable d = getResources() 
     .getDrawable(R.drawable.splashscreenlite); 
    linear.setBackgroundDrawable(d); 
    System.out.println("Image change"); 
    } 

    }; 

    splashTread = new Thread() { 
    @Override 
    public void run() { 
    try { 
    sleep(1500); 
    } catch (Exception e) { 
    } finally { 
    handler.sendEmptyMessage(1); 
    try { 
     Thread.sleep(1500); 
    } catch (InterruptedException e) { 
     // TODO Auto-generated catch block 
     e.printStackTrace(); 
    } finally { 
     SplashScreen.this.finish(); 
     startActivity(new Intent(SplashScreen.this, 
     Mainactivity.class)); 
    } 
    } 
    } 
    }; 
    splashTread.start(); 

} 
} 
相關問題