-3

My problem is, i want use RecyclerView with CollapsingToolbarLayout. But the issue is CollapsingToolbarLayout not scrolling when RecyclerView scrolling. I cant use Nested Scroll to put RecyclerView, because i want load more data to RecyclerView

<android.support.design.widget.AppBarLayout
    android:id="@+id/collapsing_toolbar_appbarlayout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="?themeColorBack">

    <android.support.design.widget.CollapsingToolbarLayout
        android:id="@+id/collapsing_toolbar_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
        app:contentScrim="?themeColorBack"
        app:layout_scrollFlags="scroll|exitUntilCollapsed">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">

            <RelativeLayout
                android:id="@+id/image_contain_relative"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:visibility="invisible">

                <android.support.constraint.ConstraintLayout
                    android:id="@+id/first_image_container"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content">

                    <ImageView
                        android:id="@+id/first_post"
                        android:layout_width="0dp"
                        android:layout_height="0dp"
                        android:layout_marginBottom="10dp"
                        android:adjustViewBounds="true"
                        android:contentDescription="@string/latest_post"
                        android:scaleType="fitXY"
                        app:layout_constraintDimensionRatio="H,16:9"
                        app:layout_constraintEnd_toEndOf="parent"
                        app:layout_constraintStart_toStartOf="parent"
                        app:layout_constraintTop_toTopOf="parent" />
                </android.support.constraint.ConstraintLayout>

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_alignBottom="@+id/first_image_container"
                    android:background="#bb000000"
                    android:orientation="vertical">

                    <TextView
                        android:id="@+id/first_image_category"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_marginTop="4dp"
                        android:paddingLeft="8dp"
                        android:paddingStart="8dp"
                        android:textColor="@color/white"
                        android:textSize="14sp"
                        tools:ignore="RtlSymmetry" />

                    <TextView
                        android:id="@+id/first_image_date"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_marginBottom="4dp"
                        android:paddingLeft="8dp"
                        android:paddingStart="8dp"
                        android:textColor="@color/white"
                        android:textSize="14sp"
                        tools:ignore="RtlSymmetry" />
                </LinearLayout>
            </RelativeLayout>

            <TextView
                android:id="@+id/first_post_title"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:padding="8dp"
                android:textColor="?themeHeadColorText"
                android:textSize="16sp"
                android:textStyle="bold" />
        </LinearLayout>

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


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

<!-- app:layout_behavior attribute value settings make app tool bar appear while RecyclerView scroll. -->
<android.support.v7.widget.RecyclerView
    android:id="@+id/post_recycle"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginBottom="60dp"
    app:layout_behavior="@string/appbar_scrolling_view_behavior" />

Tharuka Lakshan
  • 348
  • 3
  • 10
  • 1
    Welcome to SO...Please do some search on it before posting the question here. We are all here to help but first, you need to do some effort on it. Please refer this before posting question here https://stackoverflow.com/help/how-to-ask – DKV Dec 31 '18 at 06:24

2 Answers2

2

Try like this I hope this will be full fill your requirements.

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/main_content"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true">

<android.support.design.widget.AppBarLayout
    android:id="@+id/appbar"
    android:layout_width="match_parent"
    android:layout_height="250dp"
    android:fitsSystemWindows="true"
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

    <android.support.design.widget.CollapsingToolbarLayout
        android:id="@+id/collapsing_toolbar"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fitsSystemWindows="true"
        app:contentScrim="@android:color/transparent"
        app:layout_scrollFlags="scroll|exitUntilCollapsed"
        app:statusBarScrim="@android:color/transparent">

        <ImageView
            android:id="@+id/ivFeature"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fitsSystemWindows="true"
            android:scaleType="centerCrop"
            app:layout_collapseMode="parallax" />

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

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

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

<android.support.v4.widget.NestedScrollView
    android:id="@+id/nestedScrollView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:overScrollMode="never"
    app:layout_behavior="@string/appbar_scrolling_view_behavior">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">

        <android.support.v7.widget.RecyclerView
            android:id="@+id/card_recycler_view"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:nestedScrollingEnabled="false" />

    </LinearLayout>
</android.support.v4.widget.NestedScrollView>

Jaydip
  • 592
  • 5
  • 27
1

You can use like this.

<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/myCoordinatorLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

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

        <androidx.recyclerview.widget.RecyclerView
            android:id="@+id/recyclerView"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_margin="4dp" />
    </LinearLayout>

    <com.google.android.material.floatingactionbutton.FloatingActionButton
        android:id="@+id/fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="end|bottom"
        android:layout_margin="18dp"
        android:src="@drawable/ic_add" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>
Jaydip
  • 592
  • 5
  • 27
  • But it's not reach my requirement. I want scroll entire activity when scrolling my recyclerview. Top of the recyclerview has ImageView – Tharuka Lakshan Dec 31 '18 at 09:43