Help using ImageSwitcher in android
So In my program I used to use Imageviews in my layout to display images and had it so when a user pressed the Imageview it changes images. But i recently upgraded my project to version 8 and updated by SDK and i see now that there is a ImageSwitcher view under Transitions. I would like to replace my ImageViews with ImageSwitchers. Ive googled and searched all over but i cant seem to figure out how it works. I was wondering if anyone would be able to explain or show me an example of code on how to use it. What i want is very basic. I just want it to display an image from a bitmap and then when the user swipes left or right it changes the bitmap. I already have the bitmaps. I just cant figure out the code.
I tried using this code to start out but i couldnt get it to work with the bitmap
ImageSwitcher is = (ImageSwitcher) findViewById(R.id.imageSwitcher1);
is.setImageResource(bmap);
I tried using this new code to turn my bitmap into a drawable but it always crashes when run. Is there something i can fix?
Drawable d = new BitmapDrawabl开发者_如何学运维e(bmap);
ImageSwitcher is = (ImageSwitcher) findViewById(R.id.imageSwitcher1);
is.setImageDrawable(d);
setImageResource(int rsid)
takes an identifier for a resource coming from the R class
like R.drawable.foo (being foo your bitmap).
What is bmap? An actual Bitmap instance? If so use setImageDrawable()
instead
Regards, JQCorreia
Try this,
is.setImageDrawable(new BitmapDrawable(getResources(),bmap));
精彩评论