Customize your pager view with ease.
- You need to specify attribute
selector_idwith a view id andhorizontalscrollview_idwith aHorizontalScrollViewid. PagerIndicatorLayoutextendes fromRelativeLayout, which means your can put your selector view wherever you want.- You can use any view as your selector, or even a layout.
- You can put decoration in
PagerIndicatorLayoutto style your pager indicator, for example, add a foreground gradient. Checksample/there are some implementations. - You need to define a layout as a pager container in
HorizontalScrollView,LinearLayoutwithandroid:orientation="horizontal"is easier. - If you are using
LinearLayoutas your pager container, DO NOT specifyandroid:layout_gravity, otherwise it wont behave as expect. - set select callback with
PagerIndicatorLayout.setItemSelectListener(OnItemSelectListener listener) - You can use it along with
ViewPager. Check outsample/for all implementation.
Ideally a layout file would be like this:
<com.royliao.pagerindicator.PagerIndicatorLayout
android:id="@+id/lo_pi"
style="@style/PagerIndicatorLayout"
xmlns:pagerIndicator="http://schemas.android.com/apk/res-auto"
pagerIndicator:horizontalscrollview_id="@+id/hsv"
pagerIndicator:selector_id="@+id/iv_selector">
<HorizontalScrollView
android:id="@+id/hsv"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbarThumbHorizontal="@android:color/transparent">
<!-- a container for pager, no layout_gravity defined -->
<LinearLayout
android:id="@+id/lo_container"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="center_vertical"
android:orientation="horizontal">
<TextView
style="@style/Pager"
android:text="Page1" />
<TextView
style="@style/Pager"
android:text="Page2" />
<TextView
style="@style/Pager"
android:text="Page3" />
<TextView
style="@style/Pager"
android:text="Page4" />
</LinearLayout>
</HorizontalScrollView>
<!-- selector usually is set after HorizontalScrollView so that it can be on it's top -->
<ImageView
android:id="@+id/iv_selector"
android:layout_width="60dp"
android:layout_height="match_parent"
android:layout_centerInParent="true" />
</com.royliao.pagerindicator.PagerIndicatorLayout>






