16

I'm using ViewPageIndicator, specifically CirclePageIndictor in my Android application. The requirement is that the fillColor will move straight to the next circle in the indicator, without the situation like this one in the picture (the circle moves slowly and stays in the middle while paging)

How can I do this?

Cœur
  • 37,241
  • 25
  • 195
  • 267
user3414081
  • 161
  • 1
  • 1
  • 3
  • did you find solution ? I didn't get this effect with `vpi:snap="true"` or `vpi.setSnap(true);` – Logic Jan 04 '16 at 12:17

4 Answers4

36

You can try this on your xml:

<com.viewpagerindicator.CirclePageIndicator
        android:id="@+id/indicator"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:padding="10dip"
        app:radius="12dp"
        app:fillColor="@color/header_bg_color"
        app:pageColor="#ffffff"
        app:strokeColor="@color/header_bg_color"/>

and don't forget to add xmlns:app="http://schemas.android.com/apk/res-auto" on your layout. E.g

 <LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

    <android.support.v4.view.ViewPager
        android:id="@+id/pager"
        android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        />

    <com.viewpagerindicator.CirclePageIndicator
            android:id="@+id/indicator"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:padding="10dip"
            app:radius="12dp"
            app:fillColor="@color/header_bg_color"
            app:pageColor="#ffffff"
            app:strokeColor="@color/header_bg_color"/>

</LinearLayout>
marvz
  • 369
  • 2
  • 7
5

Set the snap attribute to true.

vpi:snap="true"

or

vpi.setSnap(true);
alex
  • 6,359
  • 1
  • 23
  • 21
3
final CirclePageIndicator circleIndicator = (CirclePageIndicator) findViewById(R.id.indicator);
    circleIndicator.setViewPager(_pager);
    final float density = getResources().getDisplayMetrics().density;
    circleIndicator.setFillColor(0xFFFFFFFF);
    circleIndicator.setStrokeColor(0xFFFFFFFF);
    circleIndicator.setStrokeWidth(1);
    circleIndicator.setRadius(6 * density);
Pankaj Arora
  • 10,224
  • 2
  • 37
  • 59
1

try app:snap="true"

 <com.viewpagerindicator.CirclePageIndicator
            android:id="@+id/indicator"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            app:snap="true"/>
HannahCarney
  • 3,441
  • 2
  • 26
  • 32