Code Monkey home page Code Monkey logo

pageindicatorview's Introduction

PageIndicatorView

A small, simple, animated page indicator without the need for a viewpager.

Example

Why

I built this library because I was tired of all the existing page indicators out there to require a viewpager as this prevented me from using in on an Android Wear project that time.

Usage

To use this view just include it in your depencencies using

repositories {
    ...
    maven { url "https://jitpack.io" }
}

in your project build.gradle file and

dependencies {
    compile 'com.github.markusressel:PageIndicatorView:v1.0.0'
}

in your desired module build.gradle file.

After successfull gradle build you will be able to use this in your xml layout files

<de.markusressel.android.library.pageindicatorview.PageIndicatorView
        android:id="@+id/pageIndicator"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>

If you want you can change the style of the indicators by using attributes

<de.markusressel.android.library.pageindicatorview.PageIndicatorView
        android:id="@+id/pageIndicator"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="0"
        android:paddingTop="@dimen/activity_vertical_margin"
        app:piv_activeIndicatorFillColor="?attr/colorAccent"
        app:piv_activeIndicatorFillSize="20dp"
        app:piv_activeIndicatorStrokeColor="@android:color/white"
        app:piv_activeIndicatorStrokeWidth="5dp"
        app:piv_inactiveIndicatorFillColor="?attr/colorAccent"
        app:piv_inactiveIndicatorFillSize="15dp"
        app:piv_inactiveIndicatorStrokeColor="@android:color/darker_gray"
        app:piv_inactiveIndicatorStrokeWidth="10dp"
        app:piv_pageCount="5" />

You can also set these values in code using the following methods:

pageIndicator.activeIndicatorSize = pxFromDp(this, activeIndicatorSize)
pageIndicator.activeIndicatorFillColor = activeIndicatorColorFill
pageIndicator.activeIndicatorStrokeColor = activeIndicatorColorStroke
pageIndicator.activeIndicatorStrokeWidth = pxFromDp(this, activeIndicatorStrokeWidth)

pageIndicator.inactiveIndicatorSize = pxFromDp(this, inactiveIndicatorSize)
pageIndicator.inactiveIndicatorFillColor = inactiveIndicatorColorFill
pageIndicator.inactiveIndicatorStrokeColor = inactiveIndicatorColorStroke
pageIndicator.inactiveIndicatorStrokeWidth = pxFromDp(this, inactiveIndicatorStrokeWidth)

pageIndicator.indicatorGap = pxFromDp(this, indicatorGap)

pageIndicator.pageCount = pageCount

pageIndicator.setCurrentPage(initialPageIndex)          // animated
pageIndicator.setCurrentPage(initialPageIndex, false)   // not animated

To be able to react to "OnClick" events on indicators, you can set a OnIndicatorClickedListener like this:

pageIndicator.setOnIndicatorClickedListener(object : OnIndicatorClickedListener {
    override fun onIndicatorClicked(pageIndicatorView: PageIndicatorView, index: Int) {
        // set the indicator view to the clicked position
        pageIndicatorView.setCurrentPage(index, true)

        // set your view pager to the clicked position
        viewPager.currentItem = index
    }
})

License

Copyright (c) 2016 Markus Ressel

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

pageindicatorview's People

Contributors

markusressel avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

pageindicatorview's Issues

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.