10

After switching to androidx the following code stopped working. The TextView below the Toolbar used to scroll with the content, but now it doesn't. I managed to make it work only when I set the same scrollFlags to Toolbar, but I would like to keep that in place. Is there a solution to this besides moving the Toolbar out of AppBarLayout and CoordinatorLayout?

<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">

        <androidx.appcompat.widget.Toolbar
                app:title="Non-scrollable title"
                android:layout_width="wrap_content"
                android:layout_height="?android:attr/actionBarSize"/>

        <TextView
                app:layout_scrollFlags="scroll"
                android:layout_margin="16dp"
                android:textSize="20sp"
                android:text="this should scroll with the content"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"/>

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

    <androidx.core.widget.NestedScrollView
            app:layout_behavior="@string/appbar_scrolling_view_behavior"
            android:layout_width="match_parent"
            android:layout_height="match_parent">

        <!-- some scrollable content here -->

    </androidx.core.widget.NestedScrollView>

</androidx.coordinatorlayout.widget.CoordinatorLayout>
Alireza Noorali
  • 3,129
  • 2
  • 33
  • 80

2 Answers2

7

replace attribute old: app:layout_behavior="@string/appbar_scrolling_view_behavior"

new: app:layout_behavior="com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior"

and add

implementation 'com.google.android.material:material:1.0.0'
tehnolog
  • 1,204
  • 1
  • 11
  • 23
  • 3
    Here is what saved in this resource `com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior` It is exactly same thing what you've written – Axbor Axrorov Aug 25 '20 at 11:35
0

In my case, the problem was in the margins of NestedScrollView. I removed margins from NestedScrollView and everything started work.

Axbor Axrorov
  • 2,720
  • 2
  • 17
  • 35