humam humam - 6 months ago 202
Android Question

ScrollView very slow while Scrolling

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?

Answer

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