首页 > 解决方案 > BottomSheetBehavior 填充

问题描述

我有这种片段布局。

<android.support.design.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"
    android:background="@color/colorBackgroundBlack">

    <MyCustomView
        android:id="@+id/vBottomSlider"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_behavior="android.support.design.widget.BottomSheetBehavior" />

</android.support.design.widget.CoordinatorLayout>

对于我vBottomSlider,我创建了一个BottomSheetBehavior实例:

val bh = BottomSheetBehavior.from(vBottomSlider)
bh.isHideable = false
bh.peekHeight = 50.dpToPx
bh.setBottomSheetCallback(mBottomCallback)

这就是片段内部的全部内容。

我的主要活动布局如下所示:

<android.support.constraint.ConstraintLayout
        android:id="@+id/vMainConstraint"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

     <FrameLayout
            android:id="@+id/fContent"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />

     <com.aurelhubert.ahbottomnavigation.AHBottomNavigation
            android:id="@+id/vNavigation"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:layout_constraintBottom_toBottomOf="parent" />

</android.support.constraint.ConstraintLayout>

对于我,fContent我将底部设置paddingvNavigation高度。当我向下滚动 my时,我通过更改它来vBottomSlider隐藏,并为 my设置(通过从 获取事件)。vNavigationtranslationYpaddingfContentonSlideBottomSheetBehavior.BottomSheetCallback

用手指完全滑动,效果很好。但是,当我或以编程方式为我的实例fling设置EXPANDED或状态时,它不会完全滚动。这里总是有一些空间(它似乎是我的高度)。COLLAPSEDBottomSheetBehaviorvNavigation

标签: androidkotlinmaterial-designbottom-sheet

解决方案


我已经设法通过编辑BottomSheetBehavior. 我的解决方案有点hacky。如果您需要编辑类,请发送电子邮件。


推荐阅读