dnl*_*nes 10 android material-design android-design-library
我试图实现CoordinatorLayout从最新发布的Android设计支持库,我已经按照样品用下面的代码在我的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" />
Run Code Online (Sandbox Code Playgroud)
但是,当我向下滚动视图时,操作栏不会隐藏.我无法弄清楚为什么这不起作用.
编辑:据我所知,它似乎CoordinatorLayout不起作用ListView/GridView/ScrollViews,只适用于RecyclerView和NestedScrollView.不幸的是,简单地切换到其中一个视图对我来说是不可能的,所以我仍然在寻找解决方案.
Currenlty并非所有观点都具有预期的行为CoordinatorLayout.
您的视图应该实现NestedScrollView接口并且必须处理嵌套的滚动事件.
该RecyclerView和NestedScrollView(版本22)支持这种行为.但是你也可以使用AbsListView(ListView和GridView)但只能使用API21 +.
只需添加以下内容:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
listView.setNestedScrollingEnabled(true);
}
Run Code Online (Sandbox Code Playgroud)
我相信你需要让你的ListView实现ScrollingView和NestedScrollingChild接口。
RecyclerView这不是最简单的事情,但是如果您查看的源代码,您应该能够做到。它使用了 aNestedScrollingChildHelper并且你应该能够做同样的事情。