项目作者: evan-choi

项目描述 :
Android FastScroller Example
高级语言: Java
项目地址: git://github.com/evan-choi/Android-FastScroller.git
创建时间: 2019-04-30T08:58:19Z
项目社区:https://github.com/evan-choi/Android-FastScroller

开源协议:MIT License

下载


Android-FastScroll

API Build Status

FastSroller for Android SectionIndexer interface

Supports only vertical mode in this library.

Preview

Preview

Gradle

  1. COMING SOON

Basic Usage

xml

  1. <com.steal.FastScroller
  2. android:layout_width="wrap_content"
  3. android:layout_height="wrap_content"
  4. app:fs_debug="true"
  5. app:fs_sectionHeight="24dp"
  6. app:fs_sectionWidth="24dp"
  7. app:fs_spacing="12dp"
  8. app:fs_textColor="#ff0000"
  9. app:fs_textSize="14sp"
  10. app:fs_sensitiveScroll="true"></com.steal.FastScroller>

SensitiveScroll : Raise event immediately when touch down

Setup

  1. scroller.setSectionIndexer(new SectionIndexer() {
  2. @Override
  3. public Object[] getSections() {
  4. // implements SectionIndexer.getSections
  5. }
  6. @Override
  7. public int getPositionForSection(int sectionIndex) {
  8. // implements SectionIndexer.getPositionForSection
  9. }
  10. @Override
  11. public int getSectionForPosition(int position) {
  12. // implements SectionIndexer.getSectionForPosition
  13. }
  14. });

Event Listener

  1. scroller.addOnSectionScrolledListener(new OnSectionScrolledListener() {
  2. @override
  3. public void onSectionScrolled(SectionIndexer indexer, int section) {
  4. // your code in here
  5. // ex) indexer.getPositionForSection(section)
  6. }
  7. });

in java >= 1.8

  1. scroller.addOnSectionScrolledListener((indexer, section) => {
  2. // your code in here
  3. // ex) indexer.getPositionForSection(section)
  4. });

Decoration

Interface

  1. public interface DecorationItem {
  2. void onDraw(
  3. Canvas canvas, // canvas
  4. Property<String> text, // section text
  5. Property<Paint> paint, // section text paint (TextPaint)
  6. int index, // section index
  7. int distance); // distance from section index (selected index distance is 0)
  8. }

Sample

  1. // Bolding to selected section index
  2. scroller.addDecoration(new FastScroller.DecorationItem() {
  3. @Override
  4. public void onDraw(Canvas canvas, Property<String> text, Property<Paint> paint, int index, int distance) {
  5. if (distance == 0) {
  6. paint.getValue().setTypeface(Typeface.DEFAULT_BOLD);
  7. } else {
  8. paint.getValue().setTypeface(Typeface.DEFAULT);
  9. }
  10. }
  11. });

ENJOY!