Android ImageSwitcher example

android-widget

Can anyone give me a working example of an ImageSwitcher without a Gallery?

Here's my code:

         ImageSwitcher mImageSwitcher;
         mImageSwitcher = new ImageSwitcher(this);
         mImageSwitcher.setLayoutParams(new
                ImageSwitcher.LayoutParams(
                           LayoutParams.MATCH_PARENT,LayoutParams.MATCH_PARENT));

        mImageSwitcher.setInAnimation(AnimationUtils.loadAnimation(this,
                android.R.anim.fade_in));
        mImageSwitcher.setOutAnimation(AnimationUtils.loadAnimation(this,
                android.R.anim.fade_out));
        mImageSwitcher.setFactory(this);

And I do this to display a new picture:

        Drawable d = new BitmapDrawable(bitmap);
        mImageSwitcher.setImageDrawable(d);

OK, this causes animation to the new image. How do I set the previous image in this animation?

There are two images displayed here, "previous" and "next". I know how to set the "next" image. I would like to know how to set "previous". I would expect that to be the image currently displayed, but that does not seem to be correct.

Best Solution

You can set the next image with setImageDrawable method. Of course next image can be your previous image! for example:

setImageDrawable(preimage)
Related Question