BottomSheetDialogFragment显示不全问题

BottomSheetDialogFragment在18:9以上的手机显示没问题,但是16:9以下的手机显示不全

以下是解决方案

1.先计算屏幕比例

@Override

public void onCreate(@Nullable Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

    DisplayMetrics dm =mContext.getResources().getDisplayMetrics();

    dpiRatio = (float) dm.heightPixels / (float) dm.widthPixels;

}


2.在onStart中设置PeekHeight为view的高度

@Override

public void onStart() {

super.onStart();

    if(dpiRatio >1.78){

return;

    }

if (parentView !=null ) {

View parent = (View)parentView.getParent();

        BottomSheetBehavior behavior = BottomSheetBehavior.from(parent);

        parentView.measure(0, 0);

        behavior.setPeekHeight(parentView.getMeasuredHeight());

        CoordinatorLayout.LayoutParams layoutParams = (CoordinatorLayout.LayoutParams) parent.getLayoutParams();

        layoutParams.gravity = Gravity.TOP | Gravity.CENTER_HORIZONTAL;

        parent.setLayoutParams(layoutParams);

    }

}

你可能感兴趣的:(BottomSheetDialogFragment显示不全问题)