Giter Site home page Giter Site logo

recyclerviewfastscroller's Introduction

RecyclerViewFastScroller

The RecyclerViewFastScroller is a widget that can be added to a layout and connected to a RecyclerView for fast scrolling.

This project is a demonstration of using the RecyclerViewFastScroller widget in a simple activity that uses the basic workings of com.example.android.recyclerview from the v21 Android samples.

RecyclerViewFastScroller screenshot RecyclerViewFastScroller with section indicator screenshot

As of b3e2d2f, there is now support for adding a SectionIndicator widget, which connects to the scroller. This adds functionality similar to Google's Lollipop Contacts application.

Download

You can grab the current version of the library from maven central

compile 'xyz.danoz:recyclerviewfastscroller:0.1.3'

Usage

Below are some simple steps to using a RecyclerViewFastScroller. Currently, there is only a single implementation (VerticalRecyclerViewFastScroller), so that will be used here.

The best way to check everything out is to peruse the example code and run the sample Application. See how VerticalRecyclerViewFastScroller is utilized in the recycler_view_frag.xml.

Example Code
  1. In the activity or fragment XML where your RecyclerView resides, include a VerticalRecyclerViewFastScroller object. The following example would be in a relative layout:
...
  <android.support.v7.widget.RecyclerView
      android:id="@+id/recyclerView"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      />

  <xyz.danoz.recyclerviewfastscroller.vertical.VerticalRecyclerViewFastScroller
      android:id="@+id/fast_scroller"
      android:layout_width="@dimen/however_wide_you_want_this"
      android:layout_height="match_parent"
      android:layout_alignParentRight="true"
      />
...
  1. In your fragment or activity where you setup layout programmatically, simply hook up the fast scroller to the recycler as follows:
...
  public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
      View rootView = inflater.inflate(R.layout.recycler_view_frag, container, false);
      ...
      
      // Grab your RecyclerView and the RecyclerViewFastScroller from the layout
      RecyclerView recyclerView = (RecyclerView) rootView.findViewById(R.id.recyclerView);
      VerticalRecyclerViewFastScroller fastScroller = (VerticalRecyclerViewFastScroller) rootView.findViewById(R.id.fast_scroller);
      
      // Connect the recycler to the scroller (to let the scroller scroll the list)
      fastScroller.setRecyclerView(recyclerView);
      
      // Connect the scroller to the recycler (to let the recycler scroll the scroller's handle)
      recyclerView.setOnScrollListener(fastScroller.getOnScrollListener());
      
      ...
      return rootView;
  }
...
Optional usage

There are currently a few attributes that can be used to customize the vertical fast scroller:

  <attr name="rfs_barColor" format="color|reference" />
  <attr name="rfs_barBackground" format="reference" />
  <attr name="rfs_handleColor" format="color|reference" />
  <attr name="rfs_handleBackground" format="reference" />

You can see usage of some of these in the example recycler_view_with_fast_scroller_fragment.xml which is the layout for the example app's single fragment.

SectionIndicators

Refer to RecyclerViewWithSectionIndicatorFragment and the corresponding recycler_view_with_fast_scroller_section_title_indicator_fragment.xml in order to find an implementation that adds the Lollipop-Contacts-like section indicator. In addition to the above, you will need to include the indicator in your layout (example here from recycler_view_with_fast_scroller_section_title_indicator_fragment.xml):

...
    <xyz.danoz.recyclerviewfastscroller.sample.ui.example.ColorGroupSectionTitleIndicator
      android:id="@+id/fast_scroller_section_title_indicator"
      android:layout_width="wrap_content"
      android:layout_height="@dimen/list_item_height"
      android:layout_toLeftOf="@id/fast_scroller"
      android:layout_toStartOf="@id/fast_scroller"

      recyclerviewfastscroller:rfs_backgroundColor="@android:color/white"
      recyclerviewfastscroller:rfs_textColor="@android:color/black"
       />
...

and then connect it to the scroller in the fragment:

...
    // Connect the section indicator to the scroller
    fastScroller.setSectionIndicator(sectionTitleIndicator);
...

Contribution

Feel free to submit pull requests and create issues! I will try to be vigilant about maintaining this library, but may not always be as fast as you would like ;)

recyclerviewfastscroller's People

Contributors

danoz73 avatar h6ah4i 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.