【发布时间】:2019-07-23 04:53:37
【问题描述】:
更新:
-
实际问题是
CoordinatorLayout而不是RecycleView。 - 我没有使用
RecycleView,而是在ScrollView中尝试了TextView,这是同样的问题。 - 如果您将
Toolbar用作ActionBar并将CoordinatorLayout与另一个ToolBar用作底部滚动元素的粘性标题,则某些内容未对齐
原文:
我正在开发一个视图,该视图需要 Sticky 标头实现,底部有回收视图。我使用了Coordinator layout support,如此处所述。
什么是有效的:
- 滚动列表上的粘滞视图。
- 工具栏使用
layout_collapseMode = pin和CollapsingToolbarLayout使用layout_scrollFlags = scroll|exitUntilCollapsed|snap属性。 - 具有行为
app:layout_behavior="@string/appbar_scrolling_view_behavior"的回收视图
- 工具栏使用
什么是问题:
- 回收视图在底部留边距,它的大小与我用于粘性视图的
Toolbar相同。 - 回收视图最后一项不显示,它需要额外的
bottom_margin作为粘性工具栏视图的大小。
观察:
- 如果我立即填充回收,那么它就可以工作。但是,如果延迟通知它,则会导致问题。
-
更新。 在另一次试用和运行**中,我没有使用 Recycle,而是在
NestedScrollView.(PFA) 中放置了一个TextView(此处未更新布局)- 在这里,我从 xml 添加了文本,延迟 2 秒后,只需添加更多文本,结果相同。
- 这是再次占用下边距的布局。所以没有什么与回收视图相关的具体内容,
CoordinatorLayout似乎有些问题。
我尝试了多种可用的解决方案here、here,但都没有工作。
PFA,电流输出。
更新 PFA,尝试延迟文本视图。
这是布局文件。
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.google.android.material.appbar.AppBarLayout
android:id="@+id/summaryAppBar"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.google.android.material.appbar.CollapsingToolbarLayout
android:id="@+id/main.collapsing"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_scrollFlags="scroll|exitUntilCollapsed|snap">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="256dp"
android:background="@drawable/fable_1"
app:layout_collapseMode="parallax"
app:layout_collapseParallaxMultiplier="0.3" />
<!-- This is sticky header-->
<androidx.appcompat.widget.Toolbar
android:id="@+id/summaryToolBar"
android:layout_width="match_parent"
android:layout_height="72dp"
android:layout_gravity="center"
android:background="@android:color/white"
android:padding="@dimen/common_layout_margin"
android:visibility="visible"
app:layout_collapseMode="pin"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="24sp"
android:text="Name" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:textSize="24sp"
android:text="Offer"/>
</FrameLayout>
</androidx.appcompat.widget.Toolbar>
</com.google.android.material.appbar.CollapsingToolbarLayout>
</com.google.android.material.appbar.AppBarLayout>
<!-- Bottom margin if I do't use then it does not display last child item. Wired but true in this case-->
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
android:visibility="visible"
android:layout_marginBottom="72dp"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:listItem="@layout/item_dessert" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>
【问题讨论】:
-
请分享您的代码
-
您是否已将 : android:fitsSystemWindows="true" 添加到您的协调器视图中?
-
是的,但是向上推动布局并导致操作栏从顶部切开。
-
你没有设置
android:layout_marginBottom="72dp"吗? -
@PFuster 所以我在什么是问题部分添加了问题。删除甚至不解决底部空间问题。另请参阅观察部分,到目前为止我可以得出结论。
标签: android android-toolbar android-coordinatorlayout android-collapsingtoolbarlayout stickyrecycleview