Reputation: 2696
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.
Upvotes: 1
Views: 1547
Reputation: 364604
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.
Upvotes: 3
Reputation: 3676
Supposing that you use CoordinatorLayout
as the parent layout, you need to use a RecyclerView
or NestedScrollView
to have it working properly
Upvotes: 0