BottomSheetBehavior - BottomSheet 布局在初始化后隐藏/销毁自身

问题描述 投票:0回答:0

我有自定义

Bottomsheet
布局,附有
BottomSheetBehavior
。但是在初始化之后,当我将
Bottomsheet
设置为
state
时,我立即看到
EXPANDED
卷起,但是在它的内容消失之后。我不确定是什么导致了这个问题,但我根本无法弄清楚。没有什么是强制删除代码中的
BottomSheet
内容。

BaseBottomSheet 类 - 设置行为的函数:

fun setBehaviour(v: ViewGroup){
        App.log("BaseBottomSheet: setBehaviour")
        bottomSheetBehavior = BottomSheetBehavior.from(v)
        bottomSheetBehavior?.apply {
            peekHeight = 0
            setBottomSheetState(BottomSheetBehavior.STATE_EXPANDED)
            skipCollapsed = true
            isHideable = false
        }
    }

Activity 类初始化/附加 BottomSheet 到它的通用父级:

open fun addBottomSheet(bs: BaseBottomSheet) {
        bottomSheetParent?.let {
            bottomSheet = bs
            //add custom content into layout
            it.addView(bs.getBottomSheetLayout())
            bs.setBehaviour(it)
        }
    }

bottomSheetParent - xml

 <FrameLayout
        android:id="@+id/bottomSheetContainer"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_insetEdge="bottom"
        app:layout_behavior="com.google.android.material.bottomsheet.BottomSheetBehavior">

 </FrameLayout>

FrameLayout
CoordinatorLayout
的一部分。在这个
CoordinatorLayout
里面还有其他视图(但只有上面的按钮)

bs.getBottomSheetLayout()

将返回具有独特布局(可以是任何东西)的个人

ViewGroup
的父母
BottomSheet

我什至检查了

Layout Inspector
,内容一消失,
Layout Inspector
就告诉我
FrameLayout
childCount 0
。所以后台有东西正在从该视图中删除我的附加内容。我那里没有任何
removeAllViews()
电话。

android android-layout bottom-sheet android-bottomsheetdialog
© www.soinside.com 2019 - 2024. All rights reserved.