0

How to stick linear layout at top and allow nested scrolling in Recycler view after it get stick to top of screen. Linear layout should stick as header in ScrollView then allow its children nested scrolling in recyclerview

Below is image of how initial layout will look like

enter image description here

After Scroll stick linear layout to top of screen and allow nested scrolling in recyclerview like below image

enter image description here

Below is layout xml

<?xml version="1.0" encoding="utf-8"?>
<androidx.core.widget.NestedScrollView 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:fillViewport="true"
    android:scrollbars="none"
    tools:context=".ui.fragment.HomeFragment">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:background="@drawable/background_gradient_primary">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:divider="@drawable/layout_divider_16dp"
            android:orientation="vertical"
            android:visibility="gone"
            android:showDividers="middle|end">

            <include layout="@layout/layout_toolbar_dashboard" />

            <androidx.recyclerview.widget.RecyclerView
                android:id="@+id/categoriesRecyclerView"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:clipToPadding="false"
                android:layout_marginVertical="@dimen/margin_16dp"
                android:orientation="horizontal"
                android:paddingHorizontal="@dimen/margin_16dp"
                app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
                tools:itemCount="6"
                tools:listitem="@layout/adapter_categories_item" />


        </LinearLayout>


        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical"
            android:background="@drawable/background_light_grey_top_corners">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:minHeight="36dp"
                android:gravity="center"
                android:layout_marginVertical="@dimen/margin_8dp"
                android:orientation="vertical">

                <ImageView
                    android:id="@+id/right_action"
                    android:layout_width="40dp"
                    android:layout_height="6dp"
                    android:src="@drawable/background_line_divider_icon" />

            </LinearLayout>

            <androidx.recyclerview.widget.RecyclerView
                android:id="@+id/dashboardRecyclerView"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                tools:itemCount="3"
                android:overScrollMode="never"
                tools:listitem="@layout/shimmer_category_item"
                android:padding="@dimen/margin_8dp"/>

        </LinearLayout>


    </LinearLayout>



</androidx.core.widget.NestedScrollView>
Sandeep Kumar
  • 168
  • 1
  • 9

0 Answers0