Search code examples
androidscrollbarviewflipper

How to add Scrollbar to View Flipper in android


I want to add a scroll bar to the ViewFlipper at the bottom to indicate the page flow in android. how to do it. Is there any library/method available to do that


Solution

  • It is not possible by default. but, we can use support libraries from github for doing that. Use UnderlinePageIndicator of ViewPagerIndicator for displaying scrollbar indicator in bottom of the ViewPager and use UnderlinePageIndicator of Android-ViewFlipperIndicator for displaying scrollbar indicator in bottom of the ViewFlipper.

    In Layout file: Add the indicator below the pager

    <android.support.v4.view.ViewPager
        android:id="@+id/pager"
        android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:layout_weight="1" />
    <com.viewpagerindicator.UnderlinePageIndicator
        android:id="@+id/indicator"
        android:layout_height="2dp"
        android:layout_width="fill_parent" />
    

    In Activity/Fragment: Add this indicator to pager after creating its reference

    ViewPager mPager = (ViewPager) findViewById (R.id.pager);
    UnderlinePageIndicator mIndicator = (UnderlinePageIndicator) findViewById (R.id.indicator);
    mIndicator.setViewPager(mPager);
    

    Similar approach for ViewFlipper as well