我正在尝试实施一个CoordinatorLayout
从新公布的Android 设计支持库 http://android-developers.blogspot.co.uk/2015/05/android-design-support-library.html我按照示例在 XML 布局中使用了以下代码here https://github.com/chrisbanes/cheesesquare/blob/master/app/src/main/res/layout/include_list_viewpager.xml:
<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/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
app:layout_scrollFlags="scroll|enterAlways"/>
<android.support.design.widget.TabLayout
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
android:id="@+id/viewpager"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
但是,当我向下滚动视图时,操作栏不会隐藏。我不明白为什么这不起作用。
Edit:据我所知,似乎CoordinatorLayout
不适用于ListView/GridView/ScrollViews
并且仅适用于RecyclerView
and NestedScrollView
。不幸的是,简单地切换到这些视图之一对我来说是不可能的,所以我仍在寻找解决方案。
目前,并非所有视图都具有预期的行为CoordinatorLayout
.
你的意见应该落实NestedScrollView
接口并必须处理嵌套的滚动事件。
The RecyclerView
和NestedScrollView
(版本 22)支持此行为。
但是您也可以使用AbsListView
(ListView
and GridView
)但仅限 API21+。
只需添加这样的内容:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
listView.setNestedScrollingEnabled(true);
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)