androidandroid-toolbarcoordinator-layoutandroid-includeandroid-scrollable-tabs

CoordinatorLayout scrolling does not work while Toolbar is added via <include layout =" " />


So i have been learning a tutorial to hide tool bar in CoordinatorLayout while i scroll up my view pagers first fragment but toolbar is not moving up or hiding while i scroll up.

The toolbar is added in Coordinator layout using < include layout / > tag.

But when i add tool bar directly whithout referencing it using < include layout / > (adding toolbar in Coordinator layout the way we add. DEFAULT WAY) the toolbar slides up and works.

Here is both .xml code, i dont understand why Coordinator Layout is not working with < include/> tag ?

Coordinator With include...

<android.support.design.widget.CoordinatorLayout BLAH BLAH BLAH >

    <include
        layout="@layout/toolbar_main"
        android:id="@+id/toolbar"
        app:layout_scrollFlags="scroll|enterAlways" />

Toolbar is not responding to scroll BUT

Coordinator without custom Toolbar..

<android.support.design.widget.CoordinatorLayout BLAH BLAH BLAH >

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

It WORKS! O.O BUT HOW ? And why < include tag is not working ?

here is my custom toolbar_main.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="?attr/actionBarSize"
/>

Solution

  • Try moving the line

    app:layout_scrollFlags="scroll|enterAlways"

    to inside toolbar_main.xml instead of the include statement