Make it work with CoordinatorLayout
Closed this issue · 3 comments
Hi ...
Well, I'm not sure if it's an issue or my error, but I want to use CoordinatorLayout in my layout, and when using the FastScroller, it appears in the left side, instead of the right side.
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="jahirfiquitiva.iconshowcase.activities.SearchActivity">
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:elevation="@dimen/toolbar_elevation"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_scrollFlags="scroll|enterAlways"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
</android.support.design.widget.AppBarLayout>
<android.support.v7.widget.RecyclerView
android:id="@+id/searchGrid"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
android:fitsSystemWindows="true"
android:scrollbars="none"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
<xyz.danoz.recyclerviewfastscroller.vertical.VerticalRecyclerViewFastScroller
android:id="@+id/fast_scroller"
android:layout_width="16dp"
android:layout_height="match_parent"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
/>
</android.support.design.widget.CoordinatorLayout>
And 2 things that I would like you to help me fix and/or for you to improve the lib.
- RecyclerView.setOnScrollListener is deprecated.... what could be used now?
- Make the FastScroller hide if the items are few.
Thank you.
Hi,
While I cannot help you with all of your questions, I can answer 2 of them:
- setOnScrollListener is deprecated because you can now add multiple scroll listeners with addOnScrollListener
- Try to wrap your CoordinatorLayout and RecyclerViewFastScroller in a LinearLayout or RelativeLayout to overcome your issue with the positioning.
I have this exact situation and I fixed it by wrapping the fast scroller in a simple FrameLayout
, like this:
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="?actionBarSize">
<xyz.danoz.recyclerviewfastscroller.vertical.VerticalRecyclerViewFastScroller
... />
</FrameLayout>
Thank you!
For me, it worked by wrapping the fastscroller in a RelativeLayout
, like this:
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<xyz.danoz.recyclerviewfastscroller.vertical.VerticalRecyclerViewFastScroller
android:id="@+id/fast_scroller"
android:layout_width="15dp"
android:layout_height="wrap_content"
android:layout_alignParentRight="true" />
</RelativeLayout>
And if you use app:layout_scrollFlags
in your Toolbar/AppBar, you have to put the app:layout_behavior="@string/appbar_scrolling_view_behavior"
in the RelativeLayout, otherwise the FastScroller handle will be hidden under the Toolbar in the first positions of scroll.