Dynamically change height of BottomSheetBehavior

后端 未结 9 1124
既然无缘
既然无缘 2020-12-13 03:42

I\'m using the BottomSheetBehavior from Google recently released AppCompat v23.2. The height of my bottom sheet depends on the content displayed inside of the b

9条回答
  •  余生分开走
    2020-12-13 04:23

    Though the issue has been resolved in >=24.0.0 support library, if for some reason you still have to use the older version, here is a workaround.

    mBottomSheetBehavior.setBottomSheetCallback(new BottomSheetBehavior.BottomSheetCallback() {
            @Override
            public void onStateChanged(@NonNull final View bottomSheet, int newState) {
                bottomSheet.post(new Runnable() {
                    @Override
                    public void run() {
                        //workaround for the bottomsheet  bug
                        bottomSheet.requestLayout();
                        bottomSheet.invalidate();
                    }
                });
            }
    
            @Override
            public void onSlide(@NonNull View bottomSheet, float slideOffset) {
            }
        });
    

提交回复
热议问题