Toolbar does not hide when scrolling

tries to hide the toolbar in the scroll of the list using the flags appbar_scrolling_view_behavior + scroll, but has no result, this is xml-code, cannot understand what happened to this

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.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:id="@+id/activity_main"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.lol.materialdesigntest.MainActivity">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/app_bar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="@android:color/holo_orange_light"
            app:layout_scrollFlags="scroll|enterAlways"/>

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

    <ListView
        android:id="@+id/list_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"/>

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:layout_anchor="@id/list_view"
        app:layout_anchorGravity="bottom|right"
        android:src="@mipmap/ic_launcher"
        android:layout_margin="15dp"/>

</android.support.design.widget.CoordinatorLayout>
+4
source share
3 answers

ListView has no built-in scrolls by default. Use

ViewCompat.setNestedScrollingEnabled(listView, true);

to turn it on.

Keep in mind that this will be with lollipop ahead. If you want to support older versions of Android, you should use RecyclerView

+6
source

ListView does not support nested scrolling

Use RecyclerViewinstead ListViewand enable nested scrolling inRecyclerView

+2
source

RecyclerView app:layout_behavior="@string/appbar_scrolling_view_behavior" CoordinatorLayout.

0

Source: https://habr.com/ru/post/1675038/


All Articles