/Android-FastScroller

Android FastScroller Example

Primary LanguageJavaMIT LicenseMIT

Android-FastScroll

API Build Status

FastSroller for Android SectionIndexer interface

Supports only vertical mode in this library.

Preview

Preview

Gradle

COMING SOON

Basic Usage

xml

<com.steal.FastScroller
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:fs_debug="true"
    app:fs_sectionHeight="24dp"
    app:fs_sectionWidth="24dp"
    app:fs_spacing="12dp"
    app:fs_textColor="#ff0000"
    app:fs_textSize="14sp"
    app:fs_sensitiveScroll="true"/>

SensitiveScroll : Raise event immediately when touch down

Setup

scroller.setSectionIndexer(new SectionIndexer() {
    @Override
    public Object[] getSections() {
        // implements SectionIndexer.getSections
    }

    @Override
    public int getPositionForSection(int sectionIndex) {
        // implements SectionIndexer.getPositionForSection
    }

    @Override
    public int getSectionForPosition(int position) {
        // implements SectionIndexer.getSectionForPosition
    }
});

Event Listener

scroller.addOnSectionScrolledListener(new OnSectionScrolledListener() {
    @override
    public void onSectionScrolled(SectionIndexer indexer, int section) {
        // your code in here
        // ex) indexer.getPositionForSection(section)
    }
});

in java >= 1.8

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

Decoration

Interface

public interface DecorationItem {
    void onDraw(
        Canvas canvas,         // canvas
        Property<String> text, // section text
        Property<Paint> paint, // section text paint (TextPaint)
        int index,             // section index
        int distance);         // distance from section index (selected index distance is 0)
}

Sample

// Bolding to selected section index
scroller.addDecoration(new FastScroller.DecorationItem() {
    @Override
    public void onDraw(Canvas canvas, Property<String> text, Property<Paint> paint, int index, int distance) {
        if (distance == 0) {
            paint.getValue().setTypeface(Typeface.DEFAULT_BOLD);
        } else {
            paint.getValue().setTypeface(Typeface.DEFAULT);
        }
    }
});

ENJOY!