timusus / RecyclerView-FastScroll

A simple FastScroller for Android's RecyclerView
Other
1.39k stars 182 forks source link

Scrollbar is not displayed if RecycleView is embedded into a NestedScrollView #38

Closed ikravchenko closed 6 years ago

ikravchenko commented 8 years ago

In the following layout the scroll bar does not appear:

 <android.support.v4.widget.NestedScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:clipToPadding="false"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical">

            <android.support.v7.widget.AppCompatTextView
                android:id="@+id/permission_header"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_margin="16dp"
                android:textAppearance="@style/TextAppearance.AppCompat.Medium"
                android:textStyle="bold"
                tools:text="216 Permissions:"/>

            <com.simplecityapps.recyclerview_fastscroll.views.FastScrollRecyclerView
                style="@style/FastScrollRecycleView"
                android:id="@+id/permission_list"/>

        </LinearLayout>

    </android.support.v4.widget.NestedScrollView>

where

<style name="FastScrollRecycleView">
        <item name="android:layout_width">match_parent</item>
        <item name="android:layout_height">match_parent</item>
        <item name="fastScrollAutoHide">true</item>
        <item name="fastScrollAutoHideDelay">@integer/scroll_auto_hide_delay_millis</item>
        <item name="fastScrollPopupBgColor">@color/scrolling_popup_background</item>
        <item name="fastScrollPopupTextColor">@color/scrolling_popup_text_color</item>
        <item name="fastScrollThumbColor">@color/scrolling_thumbnail_color</item>
        <item name="fastScrollPopupTextSize">@dimen/scroll_popup_text_size</item>
        <item name="fastScrollPopupBackgroundSize">@dimen/scroll_popup_background_size</item>
    </style>

Code adjustments:

recycleView.setLayoutManager(new LinearLayoutManager(getContext()));
recycleView.setNestedScrollingEnabled(false);

Library version used: 1.0.11

timusus commented 6 years ago

I've had a look into this..

When you nest a RecyclerView inside a NestedScrollView, the RecyclerViews children are all created at once (rather than as you scroll). This is ill-advised in my opinion, as you lose the benefits of 'recycling' which come with the RecyclerView.

In turn, the RecyclerView's internal draw(Canvas c) is not called as you scroll, which is the trigger for us drawing the fast scroll on the screen.

There's definitely no simple workaround for this. I would recommend you don't nest RecyclerView inside of ScrollView, but instead use a different/separate ViewTypes/ViewHolders for the views you wish to be scrolled with your RecyclerView's content.

I'm closing this issue. This feature is not supported by this library.