1

My recyclerview scrolling is laggy. It lags when I started scrolling by touching the Recyclerview, but when doesn't lag when started from the view above it. I've also disabled nestedscrolling on recyclerview.

Here is my layout:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_height="match_parent" android:layout_width="match_parent" xmlns:app="http://schemas.android.com/apk/res-auto"> <android.support.v4.widget.NestedScrollView android:layout_width="match_parent" android:layout_height="match_parent" android:scrollbars="vertical" android:overScrollMode="never"> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:focusable="true" android:focusableInTouchMode="true"> <TextView android:layout_width="match_parent" android:layout_height="200dp" android:text="HAHHAHA"/> <android.support.v7.widget.RecyclerView android:id="@+id/mRecyclerViewMain" android:layout_width="match_parent" android:layout_height="wrap_content" app:layout_behavior="@string/appbar_scrolling_view_behavior" android:background="@android:color/transparent"> </android.support.v7.widget.RecyclerView> </LinearLayout> </android.support.v4.widget.NestedScrollView> </FrameLayout> 

Here is a video to the lag. It's like the scroll is skipping some layout.

4
  • 2
    setNestedScrollView = false inside recyclerview Commented Aug 24, 2017 at 4:29
  • @PriteshVadhiya I set the nestedscrolling to false in my OnCreate() method. mRecyclerViewMain.setNestedScrollingEnabled(false); Commented Aug 24, 2017 at 4:30
  • 1
    Did You try this solution Commented Aug 24, 2017 at 4:32
  • setting recyclerview with .setHasFixedSize(true) improve the performance a bit. Thanks Commented Aug 24, 2017 at 5:17

1 Answer 1

2

Modify your xml like this:

 <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_height="match_parent" android:layout_width="match_parent" xmlns:app="http://schemas.android.com/apk/res-auto"> <android.support.v7.widget.RecyclerView android:id="@+id/mRecyclerViewMain" android:layout_width="match_parent" android:layout_height="wrap_content" app:layout_behavior="@string/appbar_scrolling_view_behavior" android:background="@android:color/transparent"> </android.support.v7.widget.RecyclerView> </FrameLayout> 

and set your textView in recyclerView's header,it will resolve your issue

<TextView android:layout_width="match_parent" android:layout_height="200dp" android:text="HAHHAHA"/> 

in adapter class set viewType for header and items list

@Override public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { if (layoutInflater == null) layoutInflater = LayoutInflater.from(parent.getContext()); if (viewType == 0) { // bind your headerview } if (viewType == 1) { //bind your recyclerview } } @Override public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) { if (holder instanceof HeaderHolder) // viewHolder for header view if (holder instanceof ListHolder) { // viewholder for list } } 

using this you can pass viewType

@Override public int getItemViewType(int position) { if (position == 0) return 0; else if (ArrayList.size() == 0) return 1; } 
Sign up to request clarification or add additional context in comments.

1 Comment

performance is a little bit better by setting .setHasFixedSize(true) in recyclerview thanks anyway

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.