项目作者: afollestad

项目描述 :
👀 Simple, compact Kotlin library for ViewPager page indicators.
高级语言: Kotlin
项目地址: git://github.com/afollestad/viewpagerdots.git
创建时间: 2018-10-14T20:41:11Z
项目社区:https://github.com/afollestad/viewpagerdots

开源协议:Apache License 2.0

下载


ViewPager Dots

This library provides a very small, compact, Kotlin-based implementation for ViewPager dots. The dots
can of course be switched out for whatever type of Drawable you wish. The animation can be
customized as well.


Maven Central
Android CI
Codacy Badge
License

Dependency

  1. dependencies {
  2. implementation 'com.afollestad:viewpagerdots:1.0.0'
  3. }

Usage

Your layout would look something like this:

  1. <LinearLayout
  2. xmlns:android="http://schemas.android.com/apk/res/android"
  3. android:layout_width="match_parent"
  4. android:layout_height="match_parent"
  5. android:orientation="vertical"
  6. >
  7. <com.afollestad.viewpagerdots.DotsIndicator
  8. android:id="@+id/dots"
  9. android:layout_width="match_parent"
  10. android:layout_height="48dp"
  11. ></com.afollestad.viewpagerdots.DotsIndicator>
  12. <androidx.viewpager.widget.ViewPager
  13. android:id="@+id/pager"
  14. android:layout_width="match_parent"
  15. android:layout_height="match_parent"
  16. ></androidx.viewpager.widget.ViewPager>
  17. </LinearLayout>

You attach the view pager to the dots indicator in your code:

  1. val viewPager: ViewPager = // ...
  2. val dots: DotsIndicator = // ...
  3. viewPager.adapter = // ... This must be set before attaching
  4. dots.attachViewPager(viewPager)

Customization

Lots of things can be visually customized about the DotsIndicator.

From your layout, here’s a list of XML attributes:

  • app:dot_width (the width of each individual dot)
  • app:dot_height (the height of each individual dot)
  • app:dot_margin (spacing between each dot)
  • app:dot_drawable (the default icon for each dot)
  • app:dot_drawable_unselected (defaults to dot_drawable)
  • app:dot_tint (lets you apply a color tint to the above drawables)
  • app:dots_animator (the animator when a dot becomes selected)
  • app:dots_animator_reverse (defaults to reversed version of the above)
  • app:dots_orientation (orientation of the whole strip; defaults to horizontal)
  • app:dots_gravity (gravity of the whole strip; defaults to center)

You can also apply some basic changes dynamically in your code:

  1. val dots: DotsIndicator = // ...
  2. // This lets you switch out the indicator drawables at runtime.
  3. dots.setDotDrawable(
  4. indicatorRes = R.drawable.some_drawable,
  5. unselectedIndicatorRes = R.drawable.other_drawable // optional, defaults to above
  6. )
  7. // These two let you dynamically tint your indicators at runtime.
  8. dots.setDotTint(Color.BLACK)
  9. dots.setDotTintRes(R.color.black)