Custom image carousel view for Android. Support featrures:
- Infinite auto-scroll (ALWAYS in one direction)
- Scrollable manually with auto-scroll
- Auto-settle to the closest position on scrolling manually
Note: The library does not provide ways for loading images from URL. You could use libraries like Glide (see the example), Picasso, Fresco or write your own.
- Only support horizontal scroll
- Only support images from URL
- Manual scroll does not work smoothly inside
NestedScrollView
This is a example of using Glide as image loader. See the example app for more details.
- Create a image loader class extend
ImageLoader
and implementloadImage
private class GlideImageLoader extends ImageLoader {
@Override
protected void loadImage(String url, final OnResourceReadyListener listener) {
// your own image loading logic here
Glide.with(ExampleActivity.this)
.load(Uri.parse(url).normalizeScheme()).asBitmap()
.into(new SimpleTarget<Bitmap>() {
@Override
public void onResourceReady(Bitmap resource, GlideAnimation<? super Bitmap> glideAnimation) {
// must call this when bitmap resource is ready
listener.onResourceReady(resource);
}
});
}
}
PS: make sure to call onResourceReady
when the image bitmap is ready
- Add
ImageCarouselView
into your layout XML
<com.f3401pal.imagecarouselview.ImageCarouselView
android:id="@+id/carouselView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
- Set the image URLs and a instance of your image loader in
ImageCarouselView
ImageCarouselView carouselView = (ImageCarouselView) findViewById(R.id.carouselView);
carouselView.setImageUrls(URLs, new GlideImageLoader());