Code Monkey home page Code Monkey logo

viewpagerindicator's Introduction

ViewPagerIndicator

The indicator for Android ViewPager2 and ViewPager.

Download

dependencies {
    implementation 'io.github.vejei.viewpagerindicator:viewpagerindicator:1.0.0-alpha.1'
}

Usage

Add Indicator to your layout:

<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android:color/white"
    tools:context=".CircleIndicatorFragment">

    <androidx.viewpager2.widget.ViewPager2
        android:id="@+id/view_pager2"
        android:layout_width="match_parent"
        android:layout_height="180dp"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintTop_toTopOf="parent"/>

    <io.github.vejei.viewpagerindicator.indicator.CircleIndicator
        android:id="@+id/circle_indicator"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="16dp"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintTop_toBottomOf="@id/view_pager2"
        app:indicatorColor="@android:color/darker_gray"
        app:indicatorSelectedColor="@color/colorAccent"
        app:indicatorGap="8dp"
        app:indicatorRadius="8dp"/>

</androidx.constraintlayout.widget.ConstraintLayout>

And setup in your fragment or activity:

PageAdapter pageAdapter = new PageAdapter();
pageAdapter.setData(Arrays.asList(activity.data));
ViewPager2 viewPager2 = view.findViewById(R.id.view_pager2);
viewPager2.setAdapter(pageAdapter);

CircleIndicator circleIndicator = view.findViewById(R.id.circle_indicator);
circleIndicator.setWithViewPager2(viewPager2, false);
circleIndicator.setItemCount(activity.data.length);
circleIndicator.setAnimationMode(CircleIndicator.AnimationMode.SLIDE);

Classes

CircleIndicator

Method Description
setWithViewPager2 Set ViewPager2 for the indicator. The userItemCount parameter indicates whether to use the item count of ViewPager2. If the value is true, the indicator use the ViewPager's item count, if it is false, you need to call setItemCount every time the adapter's dataset changed, the default value is true.
setWithViewPager Set ViewPager for the indicator. The userItemCount parameter indicates whether to use the item count of ViewPager. If the value is true, the indicator use the ViewPager's item count, if it is false, you need to call setItemCount every time the adapter's dataset changed, the default value is true.
setAnimationMode Set animation used by the indicator.
release Unregister the callback or listener of the ViewPager2(or ViewPager) and the observer of the ViewPager2(or ViewPager)'s adapter

Check the Attributes section for details of other methods.

RectIndicator

Method Description
setWithViewPager2 Set ViewPager2 for the indicator. The userItemCount parameter indicates whether to use the item count of ViewPager2. If the value is true, the indicator use the ViewPager's item count, if it is false, you need to call setItemCount every time the adapter's dataset changed, the default value is true.
setWithViewPager Set ViewPager for the indicator. The userItemCount parameter indicates whether to use the item count of ViewPager. If the value is true, the indicator use the ViewPager's item count, if it is false, you need to call setItemCount every time the adapter's dataset changed, the default value is true.
setAnimationMode Set animation used by the indicator.
release Unregister the callback or listener of the ViewPager2(or ViewPager) and the observer of the ViewPager2(or ViewPager)'s adapter

Check the Attributes section for details of other methods.

Attributes

CircleIndicator

Attribute Description Type Example Value
indicatorColor The color of unselected items. Color @android:color/darker_gray or #ddd
indicatorSelectedColor The color of selected item. Color @color/colorAccent or #ffffff
indicatorGap The gap between indicator items. Dimension 8dp
indicatorRadius The indicator item radius. Dimension 4dp
indicatorItemCount The indicators item count Integer 5

RectIndicator

Attribute Description Type Example Value
indicatorColor The color of unselected items. Color @android:color/darker_gray or #ddd
indicatorSelectedColor The color of selected item. Color @color/colorAccent or #ffffff
indicatorGap The gap between indicator items. Dimension 8dp
indicatorItemCount The indicator item count Integer 5
indicatorWidth The width of the rectangle. Dimension 24dp
indicatorHeight The height of the rectangle. Dimension 4dp
indicatorCornerRadius The rounded radius of the rectangle. radius. Dimension 0dp

Screenshots

CircleIndicator RectIndicator

Change Log

Change Log

License

MIT

viewpagerindicator's People

Contributors

vejei avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

viewpagerindicator's Issues

Auto slide attribute

Hello vejei I need to ask you if there is possiblity to add auto slide feature like will be two attributes one is boolean is auto slide or not and other for duration in milliseconds of sliding time interval

null pointer exceptions when the view is not visiable on screen

there is null point exception thrown when fragment which contain the viewpager and indicator not visible on screen. Here is stacktrace.
java.lang.NullPointerException: Attempt to invoke virtual method 'int io.github.vejei.viewpagerindicator.animation.AnimationValue$SlideAnimationValue.getCoordinateX()' on a null object reference at io.github.vejei.viewpagerindicator.painter.RectPainter$SlideAnimationPainter.draw(RectPainter.java:101) at io.github.vejei.viewpagerindicator.indicator.RectIndicator.onDraw(RectIndicator.java:175) at android.view.View.draw(View.java:16270) at android.view.View.updateDisplayListIfDirty(View.java:15267) at android.view.View.draw(View.java:16040) at android.view.ViewGroup.drawChild(ViewGroup.java:3610) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3400) at androidx.constraintlayout.widget.ConstraintLayout.dispatchDraw(ConstraintLayout.java:1882) at android.view.View.updateDisplayListIfDirty(View.java:15262) at android.view.View.draw(View.java:16040) at android.view.ViewGroup.drawChild(ViewGroup.java:3610) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3400) at androidx.constraintlayout.widget.ConstraintLayout.dispatchDraw(ConstraintLayout.java:1882) at android.view.View.updateDisplayListIfDirty(View.java:15262) at android.view.View.draw(View.java:16040) at android.view.ViewGroup.drawChild(ViewGroup.java:3610) at androidx.fragment.app.FragmentContainerView.drawChild(FragmentContainerView.java:235) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3400) at androidx.fragment.app.FragmentContainerView.dispatchDraw(FragmentContainerView.java:223) at android.view.View.updateDisplayListIfDirty(View.java:15262) at android.view.View.draw(View.java:16040) at android.view.ViewGroup.drawChild(ViewGroup.java:3610) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3400) at androidx.constraintlayout.widget.ConstraintLayout.dispatchDraw(ConstraintLayout.java:1882) at android.view.View.updateDisplayListIfDirty(View.java:15262) at android.view.View.draw(View.java:16040) at android.view.ViewGroup.drawChild(ViewGroup.java:3610) at androidx.drawerlayout.widget.DrawerLayout.drawChild(DrawerLayout.java:1478) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3400) at android.view.View.updateDisplayListIfDirty(View.java:15262) at android.view.View.draw(View.java:16040) at android.view.ViewGroup.drawChild(ViewGroup.java:3610) at androidx.fragment.app.FragmentContainerView.drawChild(FragmentContainerView.java:235) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3400) at androidx.fragment.app.FragmentContainerView.dispatchDraw(FragmentContainerView.java:223) at android.view.View.updateDisplayListIfDirty(View.java:15262) at android.view.View.draw(View.java:16040) at android.view.ViewGroup.drawChild(ViewGroup.java:3610) at androidx.fragment.app.FragmentContainerView.drawChild(FragmentContainerView.java:235) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3400) at androidx.fragment.app.FragmentContainerView.dispatchDraw(FragmentContainerView.java:223) at android.view.View.updateDisplayListIfDirty(View.java:15262) at android.view.View.draw(View.java:16040) at android.view.ViewGroup.drawChild(ViewGroup.java:3610) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3400) at androidx.constraintlayout.widget.ConstraintLayout.dispatchDraw(ConstraintLayout.java:1882) at android.view.View.updateDisplayListIfDirty(View.java:15262) at android.view.View.draw(View.java:16040) at android.view.ViewGroup.drawChild(ViewGroup.java:3610) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3400) at android.view.View.updateDisplayListIfDirty(View.java:15262) at android.view.View.draw(View.java:16040) at android.view.ViewGroup.drawChild(ViewGroup.java:3610) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3400) at android.view.View.updateDisplayListIfDirty(View.java:15262) at android.view.View.draw(View.java:16040) at android.view.ViewGroup.drawChild(ViewGroup.java:3610) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3400) at android.view.View.updateDisplayListIfDirty(View.

RTL Support

Hello vejei thank you for this library it's very useful but I need to support rtl layout. can this library support rtl

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.