1

I have implemented a toolbar that has a list slightly overlapping using the technique described here: RecyclerView with background image at top

The result looks like this:

enter image description here

As you can see the toolbar scrolls up faster than the content view. This is a nice effect but it is causing problems in my UI - how can I get the views to scroll up at the same rate?

Here's why its a problem - this is what it looks like initially:

enter image description here

And this is what happens when I start scrolling:

enter image description here

If I could just get the image to scroll up slower there wouldn't be an issue.

Here's my layout code:

<androidx.coordinatorlayout.widget.CoordinatorLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <com.google.android.material.appbar.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

        <com.google.android.material.appbar.CollapsingToolbarLayout
            android:layout_width="match_parent"
            android:layout_height="300dp"
            app:titleEnabled="false"
            app:layout_scrollFlags="scroll|exitUntilCollapsed">

            <ImageView
                android:layout_width="fill_parent"
                android:layout_height="match_parent"
                android:src="@drawable/img_runner_background"
                android:scaleType="centerCrop"
                app:layout_collapseMode="parallax" />

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginLeft="@dimen/page_padding"
                android:layout_marginRight="@dimen/page_padding"
                android:layout_marginBottom="40dp"
                android:orientation="vertical">

                <ImageView
                    android:layout_width="160dp"
                    android:layout_height="36dp"
                    android:layout_gravity="start"
                    android:layout_marginTop="30dp"
                    android:src="@drawable/logo_healthiq_white" />

            </LinearLayout>

        </com.google.android.material.appbar.CollapsingToolbarLayout>
    </com.google.android.material.appbar.AppBarLayout>

    <androidx.recyclerview.widget.RecyclerView
        android:id="@+id/list"
        android:name="com.healthiq.hiq.ui.home.HomeFragment"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:paddingBottom="@dimen/tabbar_height"
        app:layoutManager="LinearLayoutManager"
        tools:context=".ui.home.HomeFragment"
        app:behavior_overlapTop="160dp"
        app:layout_behavior="@string/appbar_scrolling_view_behavior" />

</androidx.coordinatorlayout.widget.CoordinatorLayout>
Cbas
  • 6,003
  • 11
  • 56
  • 87

0 Answers0