Dynamically change height of BottomSheetBehavior

后端 未结 9 1125
既然无缘
既然无缘 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:25

    You can use BottomSheetBehavior#setPeekHeight for that.

    FrameLayout bottomSheet = (FrameLayout) findViewById(R.id.bottom_sheet);
    BottomSheetBehavior behavior = BottomSheetBehavior.from(bottomSheet);
    behavior.setPeekHeight(newHeight);
    

    This does not automatically move the bottom sheet to the peek height. You can call BottomSheetBehavior#setState to adjust your bottom sheet to the new peek height.

    behavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
    

提交回复
热议问题