Androidx scrolling view behavior not working

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>

Upvotes: 10

Views: 5647

Answers (3)

BugsCreator
BugsCreator

Reputation: 519

I have same issue i added

app:layout_scrollFlags="scroll|enterAlways"

in appbar toolbar and this

app:layout_behavior="@string/appbar_scrolling_view_behavior"

to nested scroll bar and it works perfectly for me

Upvotes: 0

Axbor Axrorov
Axbor Axrorov

Reputation: 2806

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

Upvotes: 0

tehnolog
tehnolog

Reputation: 1214

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'

Upvotes: 7

Related Questions