开发者

How to show more than one image as splash screen in android?

I am fairly new to android. I want to show two images back to back(each one for a small duration) as splash screens in android. I am able to show a single image but struggling to show the other image.

 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();        
    }

Is there a way that I can j开发者_StackOverflow中文版ust replace the image in the ImageView ?

Thanks!!


First read the first about 5 pages of this. When onCreate runs the activity is not yet visible. So you cannot change the image in onCreate. The activity is not visible until onStart runs. You can set the image in your onCreate then in onStart launch a AsyncTask that will sleep for 1 second then load the second image and then sleep for another second and then launch your main screen.


Create a little animation like this...

http://www.codeproject.com/KB/android/AndroidSplash.aspx

And put your two images one by one to show on screen...

Happy Coding!


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();

 }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜