1

I have ScrollView which looks like the following:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools" android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin"
    tools:context="com.onecode.humam.kh.Main2Activity">


    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginTop="50dp"
        android:fillViewport="true"
        android:id="@+id/sc">

        <RelativeLayout
            android:id="@+id/partner_detail_container"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical" >

            <view
                android:id="@+id/recycler_view"
                android:layout_below="@id/recycler_view"
                android:layout_width="fill_parent"
                android:layout_height="match_parent"
                class="android.support.v7.widget.RecyclerView"/>

            <ImageButton
                android:id="@+id/button_next"
                android:layout_alignParentBottom="true"
                android:layout_alignParentRight="true"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:clickable="true"
                android:minHeight="25dp"
                android:minWidth="70dp"
                android:src="@android:drawable/ic_media_next"
                android:onClick="x"
                android:visibility="invisible"/>
        </RelativeLayout>
    </ScrollView>

    <ProgressBar
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/pb"
        android:layout_centerVertical="true"
        android:layout_centerHorizontal="true"
        android:indeterminate="false" />

</RelativeLayout>

It's very slow when scrolling, does anyone know a solution on how to solve it?

Jeff Puckett
  • 37,464
  • 17
  • 118
  • 167

2 Answers2

1

What causes the lag in scrolling is that you have nested scrollable views.

You cannot have RecyclerView inside a ScrollView.

[EDIT]

If you really need nested scrollable views that, consider using NestedSrcollView

Abdallah Alaraby
  • 2,222
  • 2
  • 18
  • 30
  • you can use [`NestedScrollView`](https://developer.android.com/reference/android/support/v4/widget/NestedScrollView.html) for that. refer to [this answer](http://stackoverflow.com/questions/31000081/how-to-use-recyclerview-inside-nestedscrollview). – Abdallah Alaraby May 27 '16 at 20:36
  • Great :) you're welcome, please don't forget to accept the answer ;) – Abdallah Alaraby May 27 '16 at 20:54
1

Try not to use RecyclerView inside ScrollView

Community
  • 1
  • 1
TarekkMA
  • 131
  • 3
  • 6