代码之家  ›  专栏  ›  技术社区  ›  Khemraj Sharma

BottomSheetDialogFragment打开一半[重复]

  •  1
  • Khemraj Sharma  · 技术社区  · 7 年前

    我的 BottomSheetDialogFragment 当我打开它时,打开一半(意思是没有完全打开)。

    fragment.show(supportFragmentManager, "my_frag")
    
    • NestedScrollView 具有 behavior_peekHeight 但没用。
    • 试过没有 嵌套滚动视图 LinearLayout .
    • 尝试在之间切换高度 match_parent &安培; wrap_content

    我有简单的 RecyclerView 底页对话框片段

    <android.support.v4.widget.NestedScrollView
            android:layout_width="match_parent"
            android:layout_height="wrap_content">
    
            <LinearLayout
                ...
                >
               <android.support.v7.widget.RecyclerView
               ...
               />
    
    2 回复  |  直到 7 年前
        1
  •  24
  •   ADM    6 年前

    BottomSheetFragment 你是说 BottomSheetDialogFragment onCreateDialog() .

     @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        BottomSheetDialog bottomSheetDialog=(BottomSheetDialog)super.onCreateDialog(savedInstanceState);
        bottomSheetDialog.setOnShowListener(new DialogInterface.OnShowListener() {
            @Override
            public void onShow(DialogInterface dialog) {
                BottomSheetDialog dialog = (BottomSheetDialog) dialog;
                FrameLayout bottomSheet =  dialog .findViewById(android.support.design.R.id.design_bottom_sheet);
                BottomSheetBehavior.from(bottomSheet).setState(BottomSheetBehavior.STATE_EXPANDED);
                BottomSheetBehavior.from(bottomSheet).setSkipCollapsed(true);
                BottomSheetBehavior.from(bottomSheet).setHideable(true);
            }
        });
        return bottomSheetDialog;
    }
    

    match_parent 无需使用 NestedScrollView . 这对我有效。如果你还面临问题,请告诉我。


    implementation 'com.google.android.material:material:1.0.0' 。 那么你需要更改家长的id FrameLayout . 会的。

     @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        BottomSheetDialog bottomSheetDialog=(BottomSheetDialog)super.onCreateDialog(savedInstanceState);
        bottomSheetDialog.setOnShowListener(new DialogInterface.OnShowListener() {
            @Override
            public void onShow(DialogInterface dia) {
                BottomSheetDialog dialog = (BottomSheetDialog) dia;
                FrameLayout bottomSheet =  dialog .findViewById(com.google.android.material.R.id.design_bottom_sheet);
                BottomSheetBehavior.from(bottomSheet).setState(BottomSheetBehavior.STATE_EXPANDED);
                BottomSheetBehavior.from(bottomSheet).setSkipCollapsed(true);
                BottomSheetBehavior.from(bottomSheet).setHideable(true);
            }
        });
        return bottomSheetDialog;
    }
    

    import com.google.android.material 在这种情况下。

        2
  •  1
  •   Jyubin Patel    7 年前

    您正在访问父视图,因此请使用下面的代码将其扩展到全屏。

    View parent = (View) inflatedView.getParent();
    parent.setFitsSystemWindows(true);
    BottomSheetBehavior bottomSheetBehavior = BottomSheetBehavior.from(parent);
    inflatedView.measure(0, 0);
    DisplayMetrics displaymetrics = new DisplayMetrics();        getActivity().getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
    int screenHeight = displaymetrics.heightPixels;
    bottomSheetBehavior.setPeekHeight(screenHeight);
    
    if (params.getBehavior() instanceof BottomSheetBehavior) {
        ((BottomSheetBehavior)params.getBehavior()).setBottomSheetCallback(mBottomSheetBehaviorCallback);
    }
    
    params.height = screenHeight;
    parent.setLayoutParams(params);
    

    希望对你有帮助。