这个效果很好:
https://www.jianshu.com/p/b770a0641a57 (https://github.com/dongjunkun/CuteIndicator)
github 星比较少。
尝试在github搜索viewpager indicator
最后使用的是:
https://github.com/romandanylyk/PageIndicatorView/releases
使用 v1.0.3的时候,编译遇到问题。(暂未排查)
降为 v1.0.0后,问题解决。
implementation 'com.romandanylyk:pageindicatorview:1.0.0'
遇到了几个问题说明:
1 样式, 默认示例代码中的 animationType 是 scale,我要的是 slide 滑动效果。还有好几种样式
具体见:
public enum AnimationType {NONE, COLOR, SCALE, WORM, SLIDE, FILL, THIN_WORM, DROP, SWAP, SCALE_DOWN}
2 大小的修改 直接改 piv_radius 即可。
<com.rd.PageIndicatorView
android:id="@+id/pageIndicatorView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:padding="2dp"
app:piv_animationType="slide"
app:piv_radius="2dp"
app:piv_dynamicCount="true"
app:piv_interactiveAnimation="true"
app:piv_selectedColor="#d8d8d8"
app:piv_unselectedColor="#c8c8c8"
app:piv_viewPager="@id/container" />
另外,对这个文章里的的改造 TabLayout 也做了尝试,比较简单,有兴趣的也可以试试,对tabLayout会有新的认识。
最后,看了一些自定义indicator的实现,可以根据 viewpager 的 addOnPageChangeListener 中的 onPageScrolled 来改变UI。
9-27补充: