【发布时间】:2017-07-13 09:07:10
【问题描述】:
我想让我的bottomsheet 最多扩展到appbar。我有带有标签的viewpager,viewpager 有appbar_scrolling_view_behavior,所以它里面的列表被滚动,toolbar 被折叠。但是底部的表格被扩展了,这是我不希望有的行为。基本上我希望折叠的bottomsheet 保持在相同的高度,并且在展开模式下它应该只展开到toolbar,无论toolbar 是否折叠。
这是我的 xml 的样子。这可行,但底部工作表也会以这种方式对appbar 崩溃作出反应。
如果我从第二个 CoordinatorLayout 中删除行为,bottomsheet 会保持原位,但会扩展到全屏。
<android.support.design.widget.CoordinatorLayout android:id="@+id/coordinator"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
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>
<FrameLayout
android:id="@+id/loadingContainer"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
... content with viewpager
</FrameLayout>
<android.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<LinearLayout
android:id="@+id/bottomSheet"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:behavior_hideable="false"
app:behavior_peekHeight="55dp"
app:layout_behavior="@string/bottom_sheet_behavior"/>
</android.support.design.widget.CoordinatorLayout>
</android.support.design.widget.CoordinatorLayout>
【问题讨论】:
-
我也遇到同样的问题你有解决办法吗?
-
在下面查看我的答案。我只能通过实现自己的处理子布局的 BottomSheetBehaviour 来解决这个问题
-
java.lang.IllegalArgumentException: 该视图与 BottomSheetBehavior 无关,请发布您的 xml 代码
标签: android android-coordinatorlayout android-appbarlayout bottom-sheet