1

I'm using the Design Support Library and I use a GridView but when I scroll up or down to the grid the Toolbar is not hiding or showing. I use the same code on a RecyclerView and it's working just fine.

<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/main_content"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/appbar"
        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/toolbar1"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            app:layout_scrollFlags="scroll|enterAlways"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />

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

    <GridView
        android:id="@+id/gridView1"
        android:numColumns="2"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"/>

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

This is my *.xml file in my activity. I just setSupportActionBar(toolbar) and initialize the GridView Adapter.

reVerse
  • 33,862
  • 21
  • 85
  • 82
Panayiotis Irakleous
  • 2,646
  • 1
  • 21
  • 34

2 Answers2

3

Currently the ListView and the GridView have the expected behavior with the CoordinatorLayout only with API>21.

To obtain this behavior you have to set:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
    gridView.setNestedScrollingEnabled(true);
}

You can find more info here.

Community
  • 1
  • 1
Gabriele Mariotti
  • 192,671
  • 57
  • 469
  • 489
0

Supposing that you use CoordinatorLayout as the parent layout, you need to use a RecyclerView or NestedScrollView to have it working properly

TheoK
  • 3,138
  • 5
  • 22
  • 33
  • Try enclosing the GridView in a NestedScrollView. From what users have been reporting so far only RecyclerView and NestedScrollView cooperate properly with the CoordinatorLayout – TheoK Jun 03 '15 at 16:43
  • The only other solution I can think of is (if possible) to transform your GridView in a RecyclerView implementing a GridLayoutManager – TheoK Jun 03 '15 at 17:00