开发者

Create slideshow without mouselistener

I am new in android and I want to create slideshow without any listener, I mean I would like open my app and see just animation wi开发者_如何学JAVAth effect. I can't find examples or tutorials, anyone could help me? Thanks


If you want to do anything automatically without user interaction, than you have to use a backgroud thread. In Android you cannot call methods modifying the UI fron a background thread. As you plan on periodically updating the UI, you will be best off with AsynchTash.

private class SwitchImagesTask extends AsyncTask<Integer, Integer, Intehger> {
     protected Long doInBackground(Integer... itemCount) {
         for (int i = 0; i < itemCount[0]; i++) {
               try{Thread.wait(1000);}catch(Exception e) {return -1;}
               publishProgress(i);
         }
         return 1;
     }

     protected void onProgressUpdate(Integer... progress) {
          // Display your image here
     }

     protected void onPostExecute(Integer result) {
          // Say goodby to the user
     }
 }

If slide show means one image after another, than the easiest way to do this will be to add an ImageView to the layout, and change it's content.


if you call a activity, you can use layout inflator in inner class which extends thread.

public class SlideshowActivity extends Activity {

private static final int[] mSlides = new int[]{R.layout.layout_a , R.layout.layout_b , R.layout.layout_c};  

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

class StartSlideShow extends Thread
{ 
    @Override
    public void run() {
        LayoutInflater inflator = SlideshowActivity.this.getLayoutInflater();
        for(int inx = 0 ; inx < mSlides.length ; inx++)
        {               
            try {
                sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            inflator.inflate(mSlides[inx], null);
        }
    }
}

}

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜