Dynamically change height of BottomSheetBehavior

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

    I faced the same issue, when trying to update the peek height based on its contents, the height from a previous layout was found. This makes sense as the new layout had not taken place yet. By posting on the UI thread the layout height is calculated after the new layout, and another layout request is made to update the bottom sheet to the right height.

    void show() {
        setVisibility(View.VISIBLE);
        post(new Runnable() {
            @Override
            public void run() {
                mBottomSheetBehavior.setPeekHeight(findViewById(R.id.sheetPeek).getHeight());
                requestLayout();
            }
        })
    }
    

提交回复
热议问题