Convert Figma logo to code with AI

JakeWharton logoViewPagerIndicator

Paging indicator widgets compatible with the ViewPager from the Android Support Library and ActionBarSherlock.

10,138
4,008
10,138
210

Top Related Projects

ImageView and FrameLayout with gestures control and position animation

An page indicator for Android ViewPager

A lightweight indicator like in nexus 5 launcher

Three material Dots Indicators for view pagers in Android !

Quick Overview

ViewPagerIndicator is an Android library that provides a customizable indicator for ViewPager components. It offers various styles of indicators, including circles, lines, and titles, to enhance the user interface and navigation experience in Android applications.

Pros

  • Easy integration with existing ViewPager implementations
  • Multiple indicator styles to choose from (e.g., circle, line, title)
  • Highly customizable appearance and behavior
  • Compatible with both Java and Kotlin Android projects

Cons

  • No longer actively maintained (last update was in 2016)
  • May require additional work to ensure compatibility with newer Android versions
  • Limited documentation and examples for advanced use cases
  • Potential performance issues with large numbers of pages

Code Examples

  1. Basic Circle Indicator:
val circleIndicator = CirclePageIndicator(this)
circleIndicator.setViewPager(viewPager)
  1. Customizing Line Indicator:
val lineIndicator = LinePageIndicator(this)
lineIndicator.setViewPager(viewPager)
lineIndicator.setSelectedColor(Color.RED)
lineIndicator.setUnselectedColor(Color.GRAY)
lineIndicator.setStrokeWidth(4f)
  1. Title Indicator with Custom Typeface:
val titleIndicator = TitlePageIndicator(this)
titleIndicator.setViewPager(viewPager)
titleIndicator.setTypeface(Typeface.createFromAsset(assets, "fonts/custom_font.ttf"))

Getting Started

  1. Add the dependency to your build.gradle file:
dependencies {
    implementation 'com.jakewharton:viewpagerindicator:2.4.1'
}
  1. Add the indicator to your layout XML:
<com.viewpagerindicator.CirclePageIndicator
    android:id="@+id/indicator"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" />
  1. Initialize the indicator in your activity or fragment:
val viewPager = findViewById<ViewPager>(R.id.view_pager)
val indicator = findViewById<CirclePageIndicator>(R.id.indicator)
indicator.setViewPager(viewPager)

Competitor Comparisons

ImageView and FrameLayout with gestures control and position animation

Pros of GestureViews

  • Offers more advanced gesture handling capabilities, including pinch-to-zoom and double-tap gestures
  • Provides smooth image transitions and animations
  • Supports both images and custom views

Cons of GestureViews

  • May have a steeper learning curve due to more complex features
  • Potentially higher performance overhead for simple use cases
  • Less focused on ViewPager integration compared to ViewPagerIndicator

Code Comparison

ViewPagerIndicator:

CirclePageIndicator indicator = (CirclePageIndicator)findViewById(R.id.indicator);
ViewPager pager = (ViewPager)findViewById(R.id.pager);
indicator.setViewPager(pager);

GestureViews:

GestureImageView imageView = findViewById(R.id.image);
imageView.getController().enableScrollInViewPager(viewPager);
imageView.getController().setOnGesturesListener(new GestureController.OnGestureListener() {
    // Implement gesture callbacks
});

The code snippets demonstrate that ViewPagerIndicator focuses on providing a simple indicator for ViewPager, while GestureViews offers more complex gesture handling capabilities for images and custom views. GestureViews requires more setup but provides greater flexibility for advanced interactions.

An page indicator for Android ViewPager

Pros of PageIndicatorView

  • More customization options for indicator appearance
  • Supports animation effects for smoother transitions
  • Actively maintained with recent updates

Cons of PageIndicatorView

  • Larger library size compared to ViewPagerIndicator
  • May have a steeper learning curve due to more configuration options

Code Comparison

ViewPagerIndicator:

CirclePageIndicator indicator = (CirclePageIndicator)findViewById(R.id.indicator);
indicator.setViewPager(pager);

PageIndicatorView:

PageIndicatorView pageIndicatorView = findViewById(R.id.pageIndicatorView);
pageIndicatorView.setCount(5); // specify total count of indicators
pageIndicatorView.setSelection(2); // specify selection

ViewPagerIndicator offers a simpler setup, directly connecting to a ViewPager. PageIndicatorView provides more granular control but requires manual configuration of count and selection.

Both libraries serve the purpose of adding page indicators to ViewPagers, but PageIndicatorView offers more modern features and customization options at the cost of a slightly more complex implementation. The choice between them depends on the specific requirements of the project and the desired level of customization.

A lightweight indicator like in nexus 5 launcher

Pros of CircleIndicator

  • More modern and actively maintained (last update in 2023)
  • Supports AndroidX and newer Android versions
  • Simpler implementation with fewer dependencies

Cons of CircleIndicator

  • Less customization options compared to ViewPagerIndicator
  • Focused solely on circle indicators, while ViewPagerIndicator offers various styles

Code Comparison

ViewPagerIndicator:

CirclePageIndicator indicator = (CirclePageIndicator)findViewById(R.id.indicator);
indicator.setViewPager(pager);
indicator.setSnap(true);

CircleIndicator:

CircleIndicator indicator = findViewById(R.id.indicator);
indicator.setViewPager(viewPager);

Summary

CircleIndicator is a more modern and streamlined library focused specifically on circle indicators for ViewPagers. It offers easier implementation and better compatibility with recent Android versions. However, ViewPagerIndicator provides more customization options and indicator styles, albeit with an older codebase.

The choice between the two depends on the specific needs of your project. If you require a simple circle indicator with modern Android support, CircleIndicator is the better option. For more complex indicator styles and extensive customization, ViewPagerIndicator might be preferable, though you may need to consider its age and potential compatibility issues with newer Android versions.

Three material Dots Indicators for view pagers in Android !

Pros of dotsindicator

  • More modern and actively maintained (last update in 2023)
  • Supports Kotlin and offers a more concise API
  • Provides additional customization options like animation duration and scale

Cons of dotsindicator

  • Less established and potentially less stable than ViewPagerIndicator
  • Fewer indicator styles available out of the box
  • May have a steeper learning curve for developers familiar with ViewPagerIndicator

Code Comparison

ViewPagerIndicator:

CirclePageIndicator indicator = (CirclePageIndicator)findViewById(R.id.indicator);
indicator.setViewPager(pager);
indicator.setFillColor(0xFF888888);
indicator.setStrokeColor(0xFF000000);

dotsindicator:

val dotsIndicator = findViewById<DotsIndicator>(R.id.dots_indicator)
dotsIndicator.attachTo(viewPager2)
dotsIndicator.setDotIndicatorColor(ContextCompat.getColor(this, R.color.colorPrimary))
dotsIndicator.setSelectedDotColor(ContextCompat.getColor(this, R.color.colorAccent))

Both libraries offer similar functionality for adding page indicators to ViewPagers, but dotsindicator provides a more modern approach with Kotlin support and additional customization options. However, ViewPagerIndicator has a longer history and may be more stable for certain use cases. The choice between the two depends on project requirements, preferred language, and desired customization options.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

Android ViewPagerIndicator

Paging indicator widgets that are compatible with the ViewPager from the Android Support Library to improve discoverability of content.

Try out the sample application on the Android Market.

ViewPagerIndicator Sample Screenshots

These widgets can also be used in conjunction with ActionBarSherlock!

Usage

For a working implementation of this project see the sample/ folder.

  1. Include one of the widgets in your view. This should usually be placed adjacent to the ViewPager it represents.

    <com.viewpagerindicator.TitlePageIndicator android:id="@+id/titles" android:layout_height="wrap_content" android:layout_width="fill_parent" />

  2. In your onCreate method (or onCreateView for a fragment), bind the indicator to the ViewPager.

    //Set the pager with an adapter
    ViewPager pager = (ViewPager)findViewById(R.id.pager);
    pager.setAdapter(new TestAdapter(getSupportFragmentManager()));
    
    //Bind the title indicator to the adapter
    TitlePageIndicator titleIndicator = (TitlePageIndicator)findViewById(R.id.titles);
    titleIndicator.setViewPager(pager);
    
  3. (Optional) If you use an OnPageChangeListener with your view pager you should set it in the indicator rather than on the pager directly.

    //continued from above
    titleIndicator.setOnPageChangeListener(mPageChangeListener);
    

Theming

There are three ways to style the look of the indicators.

  1. Theme XML. An attribute for each type of indicator is provided in which you can specify a custom style.
  2. Layout XML. Through the use of a custom namespace you can include any desired styles.
  3. Object methods. Both styles have getters and setters for each style attribute which can be changed at any point.

Each indicator has a demo which creates the same look using each of these methods.

Including In Your Project

Android-ViewPagerIndicator is presented as an Android library project. A standalone JAR is not possible due to the theming capabilities offered by the indicator widgets.

You can include this project by referencing it as a library project in Eclipse or ant.

If you are a Maven user you can easily include the library by specifying it as a dependency:

<dependency>
  <groupId>com.viewpagerindicator</groupId>
  <artifactId>library</artifactId>
  <version>2.4.1</version>
  <type>apklib</type>
</dependency>

This project depends on the ViewPager class which is available in the Android Support Library or ActionBarSherlock. Details for including one of those libraries is available on their respecitve web sites.

Developed By

Credits

License

Copyright 2012 Jake Wharton
Copyright 2011 Patrik Åkerfeldt
Copyright 2011 Francisco Figueiredo Jr.

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.