CarouselEffect
bhaveshjabuvani-credencys
117
Visit GitHub RepoCarousels

CarouselEffect

Carousel Effect with ViewPager

GifSample

Usage:

Simply add two ViewPager in FrameLayout (1. Top ViewPager for CarouselEffect, 2. Background ViewPager)

Set Top ViewPager padding left and right so previsous and next item display and also set android:clipToPadding="false"

Set Adapter for both ViewPager with same list items

<android.support.v4.view.ViewPager
        android:id="@+id/viewPagerBackground"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_gravity="center" />
        
<android.support.v4.view.ViewPager
        android:id="@+id/viewpagerTop"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:clipToPadding="false"
        android:paddingLeft="50dp"
        android:paddingRight="50dp"
        android:layout_gravity="center" />

Parallel scroll both for ViewPagers set OnPageChangeListener to Top ViewPager and override onPageScrolled() and write below logic to

@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
         int width = viewPagerBackground.getWidth();
         viewPagerBackground.scrollTo((int) (width * position + width * positionOffset), 0);
}
Become a better Android Developer
Millions of developers are learning at MindOrks

Online Training Program

Featured Blogs

Our Team

MindOrks is Certainly one of the best online blog to stay on top of all the Android development news, coding and design patterns. Finally a blog I can count on to keep myself updated with latest and greatest things happening in Android world.

Vipul Shah
Android Developer
Microsoft

Become Pro in Android by watching videos

OUR LEARNERS WORK AT