GithubHelp home page GithubHelp logo

albertsean / androidfastscroll Goto Github PK

View Code? Open in Web Editor NEW

This project forked from zhanghai/androidfastscroll

0.0 1.0 0.0 517 KB

Fast scroll for Android RecyclerView and more

Home Page: https://play.google.com/store/apps/details?id=me.zhanghai.android.fastscroll.sample

License: Apache License 2.0

Java 100.00%

androidfastscroll's Introduction

AndroidFastScroll

Android CI status GitHub release License

Fast scroll for Android RecyclerView and more.

This is not an officially supported Google product.

Why AndroidFastScroll?

  • Fully customizable: Override track, thumb, popup, animation and scrolling.
  • Easy-to-use defaults: Predefined default style, Material Design 2 style and animation.
  • Extensive view support: Out-of-box support for RecyclerView, ScrollView, NestedScrollView and WebView, plus any view with a ViewHelper implementation.
  • Window insets friendly: Support setting a separate padding for scrollbar.
  • Clean implementation: Decoupled touch handling, animation and scrolling logic.

Preview

Google Play

Sample APK

Implementation

This library is loosely based on the following AOSP implementations:

Integration

Gradle:

implementation 'me.zhanghai.android.fastscroll:library:1.1.8'

This library uses Java 8 bytecode, so you will need to enable it in your project as well:

android {
    ...
    // For Java projects
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    // For Kotlin projects
    kotlinOptions {
        jvmTarget = JavaVersion.VERSION_1_8.toString()
    }
}

Usage

Simply create a FastScroller with FastScrollerBuilder, and enjoy!

new FastScrollerBuilder(recyclerView).build();

You can also implement PopupTextProvider in your RecyclerView.Adapter to show a popup.

For more customization, please use the methods on FastScrollerBuilder. Namely:

  • setViewHelper() allows providing a custom ViewHelper to support more views.
  • setPopupTextProvider() allows providing a custom PopupTextProvider if your RecyclerView.Adapter cannot implement that interface.
  • setPadding() allows setting a custom padding for the scrollbar, instead of the padding of the view.
  • setTrackDrawable() and setThumbDrawable() allow setting custom drawables for the scrollbar. The android:state_pressed state will be updated for them so you can use a selector. The track drawable needs to have an intrinsic width and the thumb drawable needs to have an intrinsic size, in order to allow proper touch event handling.
  • setPopupStyle() allows customizing the popup view with a lambda that will receive the view.
  • setAnimationHelper() allows providing a custom AnimationHelper to use an alternative scrollbar animation.
  • disableScrollbarAutoHide() allows disabling the auto hide animation for scrollbar. This implies using a DefaultAnimationHelper.
  • useDefaultStyle() and useMd2Style() allow using the predefined styles, which sets the drawables and popup style. useDefaultStyle(), as its name suggests, is the default style when a FastScrollerBuilder is created.

The default ViewHelper implementation for RecyclerView supports both LinearLayoutManager and GridLayoutManager, but assumes that each item has the same height when calculating scroll, as there's no common way to deal with variable item height. If you know how to measure for scrolling in your specific case, you can provide your own ViewHelper implementation and fast scroll will work correctly again.

If you are using any RecyclerView.ItemDecoration that implements onDrawOver(), you might be interested in FixItemDecorationRecyclerView which can fix the drawing order.

If you are using any other library that makes use of RecyclerView.OnItemTouchListener (e.g. recyclerview-selection), you might be interested in FixOnItemTouchListenerRecyclerView which can correctly handle cancellations when dispatching touch events to listeners. You may also want to configure this library before others so that this library can take precedence in touch event handling.

You can also refer to the sample app source for how things like window insets and lift on scroll are implemented.

License

Copyright 2019 Google LLC

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

    https://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.

androidfastscroll's People

Contributors

zhanghai avatar drakeet avatar h6ah4i avatar

Watchers

James Cloos avatar

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.