android studio viewpader 圆点指示器 调研

这个效果很好:

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 滑动效果。还有好几种样式

具体见:

https://github.com/romandanylyk/PageIndicatorView/blob/4416325072f7b81ebdf0ae1eb815e2ffbdd16359/pageindicatorview/src/main/java/com/rd/animation/type/AnimationType.java

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会有新的认识。

https://essential-android.programming-books.io/viewpager-with-a-dots-indicator-ac735c60f2da4d568af36e98904b2e71

最后,看了一些自定义indicator的实现,可以根据 viewpager 的 addOnPageChangeListener 中的  onPageScrolled 来改变UI。

9-27补充:

文字指示器:https://github.com/hackware1993/MagicIndicator

图形指示器: https://github.com/zhpanvip/BannerViewPager

猜你喜欢

转载自blog.csdn.net/wuzhong8809/article/details/108781641