Android 如何正确使用CoordinatorLayout折叠列表标题(无工具栏)
我正在尝试用recyclerview实现一个简单的视差标头 这里没什么特别的。只需遵循文档、博客、指南甚至答案。但每个人都只是复制了文档,并用toobar实现了这一点。我不想要这里的工具栏。而且它不是在有协调人的情况下进行的。现有的解决方案包括向RecyclerView添加假标题项,或将标题与ListView一起使用。这似乎过时了,被协调布局体系结构淘汰了 如果我理解正确,Android 如何正确使用CoordinatorLayout折叠列表标题(无工具栏),android,android-layout,Android,Android Layout,我正在尝试用recyclerview实现一个简单的视差标头 这里没什么特别的。只需遵循文档、博客、指南甚至答案。但每个人都只是复制了文档,并用toobar实现了这一点。我不想要这里的工具栏。而且它不是在有协调人的情况下进行的。现有的解决方案包括向RecyclerView添加假标题项,或将标题与ListView一起使用。这似乎过时了,被协调布局体系结构淘汰了 如果我理解正确,appbar\u滚动\u查看\u行为只能在AppBarLayout的直接层次结构中使用。这就是它不起作用的原因。 我在支持库
appbar\u滚动\u查看\u行为
只能在AppBarLayout
的直接层次结构中使用。这就是它不起作用的原因。
我在支持库中找到了两个类:HeaderScrollingViewBehavior和HeaderBehavior。但它们是抽象的,具体的类是AppBarLayout内部的
是否有人成功实现了CoordinatorLayout的自定义行为,以便它同时支持RecyclerView和header视图?
NestedScrollView能否轻松解决此问题?(似乎不是)
我的布局以前具有以下层次结构:
DrawerLayout
CoordinatorLayout
(include code, see below)
LinearLayout fullscreen (for fragments)
FrameLayout fullscreen (for popup fragments)
AppBarLayout/Toolbar
(Some stacked layouts (constraintlayout) including "ctobar")
<android.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintTop_toBottomOf="@+id/ctobar"
app:layout_constraintBottom_toBottomOf="parent"
>
<include
android:id="@+id/collapsibleHeader"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="@+id/ctobar"
android:minHeight="10dp"
app:layout_collapseMode="parallax"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
app:layout_anchor="@+id/swipeRefresh"
app:layout_anchorGravity="top"
layout="@layout/fragment_homeroot_home_streamheader" />
<mvxui.MvxSwipeRefreshLayout2
android:id="@+id/swipeRefresh"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_constraintTop_toBottomOf="@+id/collapsibleHeader"
app:layout_constraintBottom_toBottomOf="parent"
app:MvxBind="RefreshCommand PullToRefreshCommand"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
>
<mvxui.MvxRecyclerView2
android:id="@+id/list"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_constraintTop_toBottomOf="@+id/collapsibleHeader"
app:layout_constraintBottom_toBottomOf="parent"
android:scrollbars="none"
android:divider="@color/accent"
android:animateLayoutChanges="false"
app:MvxItemTemplates="fragment_homeroot_home_streamcell_normal,fragment_homeroot_home_streamcell_unsaved"
app:MvxBind="ItemsSource StreamCells; ItemClick FlightDetailCommand"
/>
</mvxui.MvxSwipeRefreshLayout2>
</android.support.design.widget.CoordinatorLayout>
“包含”代码层次结构:
DrawerLayout
CoordinatorLayout
(include code, see below)
LinearLayout fullscreen (for fragments)
FrameLayout fullscreen (for popup fragments)
AppBarLayout/Toolbar
(Some stacked layouts (constraintlayout) including "ctobar")
<android.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintTop_toBottomOf="@+id/ctobar"
app:layout_constraintBottom_toBottomOf="parent"
>
<include
android:id="@+id/collapsibleHeader"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="@+id/ctobar"
android:minHeight="10dp"
app:layout_collapseMode="parallax"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
app:layout_anchor="@+id/swipeRefresh"
app:layout_anchorGravity="top"
layout="@layout/fragment_homeroot_home_streamheader" />
<mvxui.MvxSwipeRefreshLayout2
android:id="@+id/swipeRefresh"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_constraintTop_toBottomOf="@+id/collapsibleHeader"
app:layout_constraintBottom_toBottomOf="parent"
app:MvxBind="RefreshCommand PullToRefreshCommand"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
>
<mvxui.MvxRecyclerView2
android:id="@+id/list"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_constraintTop_toBottomOf="@+id/collapsibleHeader"
app:layout_constraintBottom_toBottomOf="parent"
android:scrollbars="none"
android:divider="@color/accent"
android:animateLayoutChanges="false"
app:MvxItemTemplates="fragment_homeroot_home_streamcell_normal,fragment_homeroot_home_streamcell_unsaved"
app:MvxBind="ItemsSource StreamCells; ItemClick FlightDetailCommand"
/>
</mvxui.MvxSwipeRefreshLayout2>
</android.support.design.widget.CoordinatorLayout>
(一些堆叠布局(constraintlayout)包括“ctobar”)
我的新布局具有以下层次结构:
DrawerLayout
CoordinatorLayout
(include code, see below)
LinearLayout fullscreen (for fragments)
FrameLayout fullscreen (for popup fragments)
AppBarLayout/Toolbar
(Some stacked layouts (constraintlayout) including "ctobar")
<android.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintTop_toBottomOf="@+id/ctobar"
app:layout_constraintBottom_toBottomOf="parent"
>
<include
android:id="@+id/collapsibleHeader"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="@+id/ctobar"
android:minHeight="10dp"
app:layout_collapseMode="parallax"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
app:layout_anchor="@+id/swipeRefresh"
app:layout_anchorGravity="top"
layout="@layout/fragment_homeroot_home_streamheader" />
<mvxui.MvxSwipeRefreshLayout2
android:id="@+id/swipeRefresh"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_constraintTop_toBottomOf="@+id/collapsibleHeader"
app:layout_constraintBottom_toBottomOf="parent"
app:MvxBind="RefreshCommand PullToRefreshCommand"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
>
<mvxui.MvxRecyclerView2
android:id="@+id/list"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_constraintTop_toBottomOf="@+id/collapsibleHeader"
app:layout_constraintBottom_toBottomOf="parent"
android:scrollbars="none"
android:divider="@color/accent"
android:animateLayoutChanges="false"
app:MvxItemTemplates="fragment_homeroot_home_streamcell_normal,fragment_homeroot_home_streamcell_unsaved"
app:MvxBind="ItemsSource StreamCells; ItemClick FlightDetailCommand"
/>
</mvxui.MvxSwipeRefreshLayout2>
</android.support.design.widget.CoordinatorLayout>
协调布局
SwipeRefreshLayout(匹配父项/匹配父项,布局行为1:自定义待定)
回收视图
MyHeaderView(匹配父/换行内容、布局行为2:自定义待定)
你会在layout\u behavior1/layout\u behavior2中添加什么?我自己写了这个解决方案,因为它似乎没有人感兴趣。也许这里的一些人会感兴趣。检查一下,因为它很长