4

How to hide toolbar when scrolling in my case? I have Activty with drawer and nested fragments. I need hiding toolbar when scrolling in Pages. How do that? Please help me.

P.S: Sorry for my English please.

Activity layout:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start">

<include
    layout="@layout/app_bar_main"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

<android.support.design.widget.NavigationView
    android:id="@+id/nav_view"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    android:fitsSystemWindows="true"
    app:headerLayout="@layout/app_nav_header_main"
    app:menu="@menu/main_drawer" />

</android.support.v4.widget.DrawerLayout>

app_bar_main.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout     
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">

<android.support.design.widget.AppBarLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:theme="@style/AppTheme.AppBarOverlay"
    app:elevation="0dp">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        app:popupTheme="@style/AppTheme.PopupOverlay" />

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

<include layout="@layout/content_main" />

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

content_main.xml:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:showIn="@layout/app_bar_main"/>

Fragment with TabLayout and ViewPager:

<ViewFlipper xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/flipper"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<include
    layout="@layout/layout_please_wait"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <android.support.design.widget.TabLayout
        android:id="@+id/tabs"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="?attr/colorPrimary"
        android:elevation="2dp"
        android:minHeight="?attr/actionBarSize"
        android:theme="@style/AppTheme.AppBarOverlay"
        app:tabIndicatorColor="@android:color/white" />

    <android.support.v4.view.ViewPager
        android:id="@+id/pager"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_behavior="@string/appbar_scrolling_view_behavior" />
</LinearLayout>

<include
    layout="@layout/layout_no_internet"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />
</ViewFlipper>

Page fragment:

<?xml version="1.0" encoding="utf-8"?>
<ViewFlipper xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/flipper"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<include
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    layout="@layout/layout_please_wait" />

<android.support.v4.widget.SwipeRefreshLayout
    android:id="@+id/refresh"
    android:layout_margin="5dp"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <ListView
        android:id="@+id/newsList"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:cacheColorHint="@android:color/transparent"
        android:divider="@null"
        android:dividerHeight="10dp"
        android:listSelector="@android:color/transparent" />

</android.support.v4.widget.SwipeRefreshLayout>

<include
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    layout="@layout/layout_news_empty" />

<include
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    layout="@layout/layout_no_internet" />

</ViewFlipper>
GPPSoft
  • 480
  • 1
  • 6
  • 15
  • The question here looks like it has good example, should work with the one minor fix described in the answer: http://stackoverflow.com/questions/33132908/drawerlayout-collapsingtoolbar-fragments-toolbar-wont-collapse-or-show-ima – Daniel Nugent May 17 '16 at 23:20
  • @Daniel Nugent, thx. But this not worked for me. Maybe because I use a ListView in fragment? I just add app:layout_collapseMode="pin", but tihs not halped me :( – GPPSoft May 17 '16 at 23:57
  • A suggestion. Try to place the tab as in this https://github.com/chrisbanes/cheesesquare sample. – razzledazzle May 18 '16 at 02:41

1 Answers1

1

ListView doesn't work with CoordinatorLayout. You must use the RecyclerView.

This is because the ListView doesn't implement interfaces like NestedScrollingChild which is essential for the scrolling behavior.

For more detail, open this.

Community
  • 1
  • 1
razzledazzle
  • 6,900
  • 4
  • 26
  • 37