0

I have issue with scrolling in my code .. here is my xml :-

<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">

<android.support.design.widget.AppBarLayout
    android:id="@+id/app_bar_layout"
    android:layout_width="match_parent"
    android:layout_height="200dp"
    android:background="@color/colorThemeDark"
    android:fitsSystemWindows="true"
    android:stateListAnimator="@drawable/appbar_always_elevated"
    android:theme="@style/AppTheme.AppBarOverlay">

    <android.support.design.widget.CollapsingToolbarLayout
        android:id="@+id/collapsing_toolbar_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fitsSystemWindows="true"
        app:collapsedTitleGravity="left"
        app:contentScrim="@color/colorThemeDark"
        app:expandedTitleGravity="center|bottom"
        app:expandedTitleTextAppearance="@style/ExpandedAppBar"
        app:layout_scrollFlags="scroll|exitUntilCollapsed|snap">

        <de.hdodenhof.circleimageview.CircleImageView
            android:id="@+id/circleView"
            android:layout_width="80dp"
            android:layout_height="80dp"
            android:layout_centerHorizontal="true"
            android:layout_gravity="center_vertical|center_horizontal"
            android:src="@drawable/main_logo"
            app:layout_collapseMode="none" />

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?android:attr/actionBarSize"
            android:theme="@style/ThemeOverlay.AppCompat.Light"
            app:layout_collapseMode="pin" />

    </android.support.design.widget.CollapsingToolbarLayout>

</android.support.design.widget.AppBarLayout>

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#323642"
    app:layout_behavior="@string/appbar_scrolling_view_behavior">

    <RelativeLayout
        android:id="@+id/firstText"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="5dp"
        android:paddingLeft="10dp">

        <TextView

            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="What you learn today?"
            android:textColor="@color/colorWhite"
            android:textStyle="bold" />
    </RelativeLayout>


    <android.support.v7.widget.RecyclerView
        android:id="@+id/catBoxes"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/firstText"
        android:layout_marginTop="5dp"
        android:paddingLeft="5dp"
        android:paddingRight="5dp" />

    <RelativeLayout
        android:id="@+id/secondText"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/catBoxes"
        android:paddingLeft="10dp">

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Recommended for you"
            android:textColor="@color/colorWhite"
            android:textStyle="bold" />
    </RelativeLayout>

    <android.support.v7.widget.RecyclerView
        android:id="@+id/catMenu"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@+id/secondText"
        android:layout_marginTop="5dp"
        app:layout_behavior="@string/appbar_scrolling_view_behavior" </android.support.v7.widget.RecyclerView>
</RelativeLayout></android.support.design.widget.CoordinatorLayout>

I have two different recyclerView in single Activity.as in my code , i take root element as CoordinatorLayout. i add two RecyclerView in my code.when i scroll my recyclerview it scroll only first recyclerView and second RecyclerView scroll below first recyclerview. but i want to both recyclerView scroll at same time when i scroll up my screen.

Gif with my problem. Green boxes scrolled but i want to stop this green boxes scrolling

Boken
  • 4,825
  • 10
  • 32
  • 42
  • are kehna kya chahte ho? – debo.stackoverflow May 26 '18 at 11:11
  • i have 2 recyclerview in my single CoordinatorLayout, when i scroll activity first recyclerview scroll up and second also but second recyclerview also scroll below first recyclerview . i want to stop this below scroll for second recyclerview. –  May 26 '18 at 11:40

1 Answers1

0

When you have two recycler view in a view and you want them to use all the space, you need to use NestedScrollView.

Your code will be the following:

<android.support.v4.widget.NestedScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#323642"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">

        <RelativeLayout
            android:id="@+id/firstText"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="5dp"
            android:paddingLeft="10dp">

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="What you learn today?"
                android:textColor="@color/colorWhite"
                android:textStyle="bold" />
        </RelativeLayout>

        <android.support.v7.widget.RecyclerView
            android:id="@+id/catBoxes"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@id/firstText"
            android:layout_marginTop="5dp"
            android:paddingLeft="5dp"
            android:paddingRight="5dp" />

        <RelativeLayout
            android:id="@+id/secondText"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@id/catBoxes"
            android:paddingLeft="10dp">

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="Recommended for you"
                android:textColor="@color/colorWhite"
                android:textStyle="bold" />
        </RelativeLayout>

        <android.support.v7.widget.RecyclerView
            android:id="@+id/catMenu"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_below="@+id/secondText"
            android:layout_marginTop="5dp"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
    </RelativeLayout>
</android.support.v4.widget.NestedScrollView>

And in your code, use this in both recycler view:

LayoutManager layoutManager = new LinearLayoutManager(this);
layoutManager.setAutoMeasureEnabled(true);
recyclerView.setLayoutManager(layoutManager);
recyclerView.setNestedScrollingEnabled(false);

More info in smbd uknow`s answer here

jonathanrz
  • 4,206
  • 6
  • 35
  • 58
  • not working for me . please see my attach link in my question @jonathanrz –  May 28 '18 at 08:01