我在 CoordinatorLayout 中的自定义视图面临以下问题:滚动 RecyclerView 时需要折叠 ViewGroup (fe LinearLayout)。ViewGroup 充当 RecyclerView 的标头。使用以下代码时:
<android.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_height="wrap_content"
android:layout_width="match_parent">
<LinearLayout
android:id="@+id/header"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_scrollFlags="scroll|enterAlways"
android:orientation="vertical">
<!-- TextViews, etc. -->
</LinearLayout>
</LinearLayout>
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerView"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</android.support.design.widget.CoordinatorLayout>
即使我尝试将具有适当值的属性 app:layout_bevahiour 添加到回收站的标题中,它也不起作用。RecyclerView 将占据所有屏幕,并且 header(LinearLayout) 不会显示。但是当我将 LinearLayout 更改为 AppBarLayout 时,一切都像魅力一样,但标题被设置为操作栏。
对于任何 ViewGroup(fe LinearLayout),有什么方法可以实现与 AppBarLayout 相同的行为吗?