-
Notifications
You must be signed in to change notification settings - Fork 554
5.x | FastScroller
- XML Configuration
- Java initialization
- Callbacks
- Customization
FastScroller needs an XML layout and Java initialization. The layout has to be placed at the end of the view hierarchy after everything else has been declared:
...
<android.support.v7.widget.RecyclerView
.../>
...
<!-- FastScroller Layout must be at the end of ViewHierarchy
in order to be displayed at the top of every views -->
<include layout="@layout/fast_scroller"/>
</FrameLayout>
Here is the layout/fast_scroller.xml
<eu.davidea.fastscroller.FastScroller
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/fast_scroller"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_centerHorizontal="true"
android:layout_alignTop="@+id/swipeRefreshLayout"
android:layout_alignBottom="@+id/swipeRefreshLayout"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:visibility="gone"
tools:visibility="visible"/>
In the creation of the Activity/Fragment call setFastScroller()
after the Adapter has been attached to the RV:
//First, assign the Adapter to the RV
mRecyclerView.setAdapter(mAdapter);
//Add FastScroll to the RecyclerView
//stateChangeListener is optional and might be the Activity
mAdapter.setFastScroller((FastScroller) findViewById(R.id.fast_scroller),
Utils.getColorAccent(context)[, stateChangeListener]);
A useful callback is triggered when the handle is draggeded, the method onFastScrollerStateChange()
is called.
From the Activity, implement the callback method:
@Override
public void onFastScrollerStateChange(boolean scrolling) {
//Example
if (scrolling) hideFab();
else showFab();
}
The text is built from the Adapter callback. It has to be implemented/overridden from the inside of a CustomAdapter that extends FlexibleAdapter:
@Override
public String onCreateBubbleText(int position) {
IFlexible iFlexible = getItem(position);
return iFlexible.toString().substring(0,1).toUpperCase();
}
The following 3 methods give full control on the FastScroller
instance:
/**
* Changes the visibility of the View
*/
public void toggleFastScroller();
/**
* Returns true, if FastScroller is configured and shown, false otherwise
*/
public boolean isFastScrollerEnabled();
/**
* Returns the FastScroller instance for more control on the settings.
*/
public FastScroller getFastScroller();
FastScroller is composed by:
- drawable/fast_scroller_bubble.xml
- drawable/fast_scroller_handle.xml
- layout/library_fast_scroller_layout.xml
Note: The Resources can be overridden by assigning the same @+id
to the views of the base layout.
The previous Drawables and XML create the following preview:
- Update Data Set
- Selection modes
- Headers and Sections
- Scrollable Headers and Footers
- Expandable items
- Drag&Drop and Swipe
- EndlessScroll / On Load More
- Search Filter
- FastScroller
- Adapter Animations
- Third party Layout Managers
- Payload
- Smooth Layout Managers
- Flexible Item Decoration
- Utils
- ActionModeHelper
- AnimatorHelper
- EmptyViewHelper
- UndoHelper
* = Under revision!