ViewPagerIndicator README

The project's README from github.com/JakeWharton/ViewPagerIndicator. As one markdown file: README.md.

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.

ViewPagerIndicator (JakeWharton/ViewPagerIndicator)

Searching Database…

10.1K ·GitHub
archived
这是什么?这是一套 Android 翻页指示器控件,配合 Android Support Library 或 ActionBarSherlock 里的 ViewPager 使用,显示用户当前所在的位置,让内容更容易被发现。
它是一个应用,还是要添加到我自己的 Android 项目里的东西?它是一个 Android library 项目,需要包含到你自己的应用中,而不是一个独立的 JAR —— 之所以不能做成 JAR,是因为它的主题样式需要用到这个库自带的资源文件。
我怎么把它添加到我的项目里?在 Eclipse 或 ant 中把它作为 Android library 项目引用,或者添加 Maven 依赖 com.viewpagerindicator:library:2.4.1(apklib)。仓库里的 sample/ 文件夹包含一个完整可运行的示例。
我的应用还需要别的东西才能让这些指示器工作吗?需要 —— 你的项目还必须包含提供 ViewPager 类的库:Android Support Library 或 ActionBarSherlock。它们的配置详情见各自的网站。
这个项目还在积极维护吗?没有 —— GitHub 仓库已归档为只读,代码停留在 2011 到 2012 年,面向的是 Eclipse/ant 和 Maven 那个年代。要想在现代 Android 构建中使用,需要先自行改造。
我怎么把指示器和我的 ViewPager 关联起来?把指示器控件加到布局里、放在 ViewPager 旁边,然后在 onCreate(Fragment 里则是 onCreateView)中调用 indicator.setViewPager(pager)。如果你要用 OnPageChangeListener,应把它设置到指示器上,而不是直接设置到 pager 上。
我可以改变指示器的外观吗?可以,有三种方式:在主题 XML 里使用 style 属性、在布局 XML 里通过自定义命名空间使用样式,或者在运行时通过指示器对象的 getter 和 setter 来设置。
它包含哪些指示器样式?用法示例中展示的是 TitlePageIndicator,致谢部分说明标题指示器和圆点指示器最初来自 Patrik Åkerfeldt 的 ViewFlow。每种类型的指示器都有对应的属性,并且在示例应用里都有自己的演示。
它支持 Fragment 吗?支持 —— 致谢中列出了 Francisco Figueiredo Jr.,感谢他提出并通过 ViewPager 实现了对 Fragment 支持的最初方案,示例应用中就是用 getSupportFragmentManager() 来绑定 pager 的。
Size
8.5 MB
Stars
10.1K
Updated
CommitSep 12
Age
15y
Commits · 90 Days