【发布时间】:2019-02-15 19:35:39
【问题描述】:
我有一个持久的底部工作表(基本上是一个按钮)和一个回收器视图,它们都包含在 CoordinatorLayout 中。
当底部工作表展开时,我不希望它遮挡回收站视图。我可以通过分别在底部工作表中设置app:layout_insetEdge="bottom" 和在回收站视图中设置app:layout_dodgeInsetEdges="bottom" 来实现这一点。
但是,由于回收站视图的高度设置为android:layout_height="match_parent",因此当底部工作表展开时,其顶部会部分移出屏幕。
相反,我希望回收站视图根据底部工作表的高度动态调整其高度,使其不再移出屏幕。我怎样才能做到这一点?
这是完整的布局:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:id="@+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:nestedScrollingEnabled="false"
app:layout_dodgeInsetEdges="bottom" />
<Button
android:id="@+id/bottom_sheet"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/update_all"
android:foreground="?attr/selectableItemBackground"
android:background="@drawable/angled_button"
app:behavior_hideable="false"
app:behavior_peekHeight="0dp"
app:layout_insetEdge="bottom"
app:layout_behavior="android.support.design.widget.BottomSheetBehavior" />
</android.support.design.widget.CoordinatorLayout>
编辑:添加截图
编辑 2:添加 GIF
【问题讨论】:
-
its top partly moves out of the screen when the bottom sheet is expanded.加个 gif 或图片能详细说明一下吗?非常感谢。 -
你试过删除这个吗?:
android:nestedScrollingEnabled="false" -
没有变化,只是过度滚动效果消失了。
-
为什么不让底部的工作表覆盖
RecyclerView的底部?如果您删除layout_dodgeInsetEdges和layout_insetEdge,您将拥有您想要的外观,或者,您的实际布局是否比您在此处展示的更复杂? -
尝试使用带有 ToolBar 而不是 ActionBar 的 AppBarLayout。还将
app:layout_behavior="@string/appbar_scrolling_view_behavior"添加到您的 RecyclerView。
标签: android user-interface material-design android-coordinatorlayout bottom-sheet