Search code examples
androidandroid-layoutandroid-recyclerviewandroid-scrollviewandroid-scroll

Android: Recycler view inside ScrollView is not working


I am trying to put RecyclerView inside ScrollView, I Have layout above the recycler view, so I want to scroll both layout and recycler while scrolling.

In My main Layout I have two sub Layout , and one of the have recyclerView and another one Have an Image .Both layout inside a scrollView. When I scrolling up in the layout , I want to scroll both

I know the issue that we cant put two scroll view in one layout. Am searching is there any logic that we can scroll both layout and recycler View

Layout.xml

<?xml version="1.0" encoding="utf-8"?>
 <LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/backgorund"
android:weightSum="1">

 <ScrollView
    android:id="@+id/scrollView1"

    android:layout_width="match_parent"
    android:fillViewport="true"
android:layout_height="match_parent" >

<LinearLayout

    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:weightSum="1">
<LinearLayout
    android:id="@+id/layout_top_balance"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight=".25">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <TextView
            android:id="@+id/txt_balance"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
            android:textSize="35dp"
            android:textColor="@color/black"
            android:text="$60 USD"/>
        <TextView
            android:layout_below="@+id/txt_balance"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
            android:textSize="20dp"
            android:textColor="#828282"
            android:text="Account Balance"/>
    </RelativeLayout>
</LinearLayout>
<LinearLayout
    android:id="@+id/layout_feeds"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:paddingLeft="16dp"
    android:paddingBottom="5dp"
    android:layout_weight=".75">

    <view
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        class="android.support.v7.widget.RecyclerView"
        android:id="@+id/recycler_view"
        android:layout_alignParentStart="true"
        android:layout_alignParentLeft="true"/>
</LinearLayout>
    </LinearLayout>
</ScrollView>

Cam any one please help for solving this issue:)


Solution

  • It is not recommended to scroll inside scroll in android. Recycler view is itself a scroll. Seems you want a scrollable portion above a list "layout_top_balance". Add this view as header of recycler view and remove scrollview. This will solve your problem.