在build.gradle里面添加依赖
implementation 'com.tbuonomo:dotsindicator:4.2'
implementation 'androidx.viewpager2:viewpager2:1.0.0-alpha01'
首先是xml布局
activity_view.xml
<androidx.viewpager2.widget.ViewPager2
android:id="@+id/view_pager"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="@+id/tv_skip"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="@+id/indicator"
app:layout_constraintVertical_bias="0.558" />
<com.tbuonomo.viewpagerdotsindicator.WormDotsIndicator
android:id="@+id/indicator"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="20dp"
android:layout_marginLeft="16dp"
android:layout_marginBottom="44dp"
app:dotsColor="@color/colorglary"
app:dotsSize="10dp"
app:dotsSpacing="10dp"
app:dotsStrokeColor="@color/colorglary"
app:layout_constraintBottom_toBottomOf="parent"
app