Gridview 不是 showing/hiding 工具栏
Gridview not showing/hiding toolbar
我正在使用设计支持库并使用 GridView
,但是当我向上或向下滚动到网格时,Toolbar
没有隐藏或显示。我在 RecyclerView
上使用相同的代码,它工作得很好。
<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>
这是我 activity 中的 *.xml 文件。我只是 setSupportActionBar(toolbar)
并初始化 GridView 适配器。
假设您使用 CoordinatorLayout
作为父布局,您需要使用 RecyclerView
或 NestedScrollView
才能使其正常工作
目前 ListView
和 GridView
仅在 API>21 中具有与 CoordinatorLayout
的预期行为。
要获得此行为,您必须设置:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
gridView.setNestedScrollingEnabled(true);
}
您可以找到更多信息 。
我正在使用设计支持库并使用 GridView
,但是当我向上或向下滚动到网格时,Toolbar
没有隐藏或显示。我在 RecyclerView
上使用相同的代码,它工作得很好。
<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>
这是我 activity 中的 *.xml 文件。我只是 setSupportActionBar(toolbar)
并初始化 GridView 适配器。
假设您使用 CoordinatorLayout
作为父布局,您需要使用 RecyclerView
或 NestedScrollView
才能使其正常工作
目前 ListView
和 GridView
仅在 API>21 中具有与 CoordinatorLayout
的预期行为。
要获得此行为,您必须设置:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
gridView.setNestedScrollingEnabled(true);
}
您可以找到更多信息