gpt4 book ai didi

android - BottomSheetBehavior : The view is not associated with BottomSheetBehavior

转载 作者:行者123 更新时间:2023-12-03 03:27:44 25 4
gpt4 key购买 nike

我正在使用 Google 设计支持库 25.0.0在我的 Activity 中,我有一个相对布局

app:layout_behavior="android.support.design.widget.BottomSheetBehavior"

现在,当我引用它来添加 BottomSheetBehaviour 时,我收到错误

java.lang.IllegalArgumentException: The view is not associated with BottomSheetBehavior

这是布局:

<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:map="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/maps_colayout"
xmlns:app="http://schemas.android.com/tools"
android:fitsSystemWindows="true"
android:background="@color/white">

...

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="280dp"
android:layout_gravity="bottom"
android:id="@+id/rl_bottomsheet"
android:background="#F3F3F3"
app:layout_behavior="android.support.design.widget.BottomSheetBehavior">

...

</RelativeLayout>

这是与 Activity 相关的代码:

CoordinatorLayout colayout = (CoordinatorLayout) findViewById(R.id.maps_colayout);
View bottomSheet = colayout.findViewById(R.id.rl_bottomsheet);
BottomSheetBehavior behavior = BottomSheetBehavior.from(bottomSheet);
behavior.setBottomSheetCallback(new BottomSheetBehavior.BottomSheetCallback() {
@Override
public void onStateChanged(@NonNull View bottomSheet, int newState) {
// React to state change
}

@Override
public void onSlide(@NonNull View bottomSheet, float slideOffset) {
// React to dragging events
}
});

最佳答案

您需要在线性布局标记中添加此行。正在引用的那个。

app:layout_behavior="android.support.design.widget.BottomSheetBehavior"

或适用于 androidx

app:layout_behavior="com.google.android.material.bottomsheet.BottomSheetBehavior"

关于android - BottomSheetBehavior : The view is not associated with BottomSheetBehavior,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40693310/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com