Reputation: 769
I have a recyclerView
as below. This is inside a fragment
which is the first screen that is displayed when the app launches. Before I add the NestedScrollView
, the recyclerView
used to load the data fast (or the recyclerView was displayed immediately). Now, after adding NestedScrollView
it takes some time for the recyclerView
to load the data (or to display the recyclerView).
I don't know whether the recyclerView is displayed late or the data is loaded slowly.
Note: Once it's shown, there is no issue when scrolling, items are loaded at normal speed on scroll. The issue is only at initial loading.
<?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"
android:background="@color/colorOffWhite"
android:orientation="vertical"
tools:context=".ui.fragments.HomeFragment">
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusableInTouchMode="false"
android:orientation="vertical">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.viewpager2.widget.ViewPager2
android:id="@+id/vp_deals"
android:layout_width="match_parent"
android:layout_height="200dp"
android:orientation="horizontal"
android:visibility="gone"
tools:visibility="visible"/>
<TextView
android:id="@+id/tv_all_deals"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/colorWhite"
android:text="All Deals"
android:layout_gravity="bottom|right"
android:layout_marginEnd="5dp"
android:layout_marginBottom="3dp"
android:background="@drawable/app_gradient_color_background"
android:padding="3dp"
android:clickable="true"
android:focusable="true"
android:foreground="?android:attr/selectableItemBackgroundBorderless"/>
</FrameLayout>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rv_home_items"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:nestedScrollingEnabled="false"
android:focusableInTouchMode="true"/>
</LinearLayout>
</androidx.core.widget.NestedScrollView>
</RelativeLayout>
Upvotes: 1
Views: 1391
Reputation: 5351
First: check the size of the images and reduce the size of the images
Second: You must disable nestedScrollingEnabled
android:nestedScrollingEnabled="false"
Upvotes: 0
Reputation: 411
This is a a common problem when you try to create recyclerview inside NestedScrollView cause the recycler view height not defined
try to set recyclerview.setNestedScrollingEnabled(false);
I think it will solve that problem
Also, it's better to define a certain height for recycler view when it is placed inside a nestedScrollView
Upvotes: -2