Android ImageSwitcher example

余生颓废 提交于 2019-12-12 12:07:06

问题


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.


回答1:


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

setImageDrawable(preimage)


来源:https://stackoverflow.com/questions/9987839/android-imageswitcher-example

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!