Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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>
like image 465
Євген Гарастович Avatar asked Apr 12 '19 10:04

Євген Гарастович


1 Answers

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'
like image 106
tehnolog Avatar answered Oct 13 '22 22:10

tehnolog