小编Har*_*rma的帖子

BottomSheetBehaviour:视图与BottomSheetBehavior无关

我正在使用Google Design Support Library 25.0.0在我的活动中,我有一个相对布局

app:layout_behavior="android.support.design.widget.BottomSheetBehavior"
Run Code Online (Sandbox Code Playgroud)

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

java.lang.IllegalArgumentException: The view is not associated with BottomSheetBehavior
Run Code Online (Sandbox Code Playgroud)

这是布局:

<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>
Run Code Online (Sandbox Code Playgroud)

这是活动相关代码:

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 …
Run Code Online (Sandbox Code Playgroud)

android android-design-library androiddesignsupport bottom-sheet

17
推荐指数
3
解决办法
1万
查看次数