Reputation: 151
I'm having a really weird issue I've never experienced before.
So, I have a view (BottomSheet) that encapsulates a RecyclerView
and its empty view. I put one of them as View.GONE
and the other as View.VISIBLE
, depending on if there are items to show or not.
The empty view is actually wrapped in a NestedScrollView
because I need to be able to scroll it for the user to be able to move the BottomSheet up or down.
The problem is that, depending on how I structure the view, the scroll is actually on the RecyclerView
or the NestedScrollView
, whichever I put first, and not both. Their parent is a RelativeLayout
(take a look at the code below).
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
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"
style="@style/BottomSheet"
>
<androidx.core.widget.NestedScrollView
android:id="@+id/empty_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone"
tools:visibility="visible"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal"
android:layout_marginTop="115dp"
android:orientation="vertical"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_marginTop="7dp"
android:textAlignment="center"
/>
</LinearLayout>
</androidx.core.widget.NestedScrollView>
<com.myproject.CustomRecyclerView
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
android:paddingBottom="36dp"
android:paddingTop="10dp"
app:emptyView="@id/empty_view"
/>
</RelativeLayout>
Upvotes: 4
Views: 382
Reputation: 332
1.- Put in your NestedScrollView this :
android:overScrollMode="never"
Now what kinda problem occurred when we used nestedScrollView and put recyclerView inside nestedScrollView, it scrolls in various speed depending on gesture. The scrolling feature will not be smooth.
2.-So to fix this issue all you have to do after setting your adapter put this line:
ViewCompat.setNestedScrollingEnabled(recyclerView, false);
Now your recyclerview will work with smooth scrolling…
I hope It will help you!
Upvotes: 1