Dynamically change height of BottomSheetBehavior

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

    I had the same problem with RelativeLayout as my bottom sheet. The height won't be recalculated. I had to resort to setting the height by the new recalculated value and call BottomSheetBehavior.onLayoutChild.

    This is my temporary solution:

    coordinatorLayout = (CoordinatorLayout)findViewById(R.id.coordinator_layout);
    bottomSheet = findViewById(R.id.bottom_sheet);
    
    int accountHeight = accountTextView.getHeight();
    accountTextView.setVisibility(View.GONE);
    
    bottomSheet.getLayoutParams().height = bottomSheet.getHeight() - accountHeight;
    bottomSheet.requestLayout();
    behavior.onLayoutChild(coordinatorLayout, bottomSheet, ViewCompat.LAYOUT_DIRECTION_LTR);
    

提交回复
热议问题