zoukankan      html  css  js  c++  java
  • BottomSheetDialogFragment 如何设置高度和禁止滑动

    主要是获取dialog 的BottomSheetBehavior 然后设置 setPeekHeightBottomSheetCallback.

    private BottomSheetBehavior.BottomSheetCallback mBottomSheetBehaviorCallback = new BottomSheetBehavior.BottomSheetCallback() {
            @Override
            public void onStateChanged(@NonNull View bottomSheet, int newState) {
                //禁止拖拽,
                if (newState == BottomSheetBehavior.STATE_DRAGGING) {
                    //设置为收缩状态
                    mBottomSheetBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
                }
            }
            @Override
            public void onSlide(@NonNull View bottomSheet, float slideOffset) {
            }
        };
    
        @Override
        public void onStart() {
            super.onStart();
            Dialog dialog = getDialog();
    
            if (dialog != null) {
                View bottomSheet = dialog.findViewById(R.id.design_bottom_sheet);
                bottomSheet.getLayoutParams().height = ViewGroup.LayoutParams.MATCH_PARENT;
            }
            final View view = getView();
            view.post(new Runnable() {
                @Override
                public void run() {
                    View parent = (View) view.getParent();
                    CoordinatorLayout.LayoutParams params = (CoordinatorLayout.LayoutParams) (parent).getLayoutParams();
                    CoordinatorLayout.Behavior behavior = params.getBehavior();
                    mBottomSheetBehavior = (BottomSheetBehavior) behavior;
                    mBottomSheetBehavior.setBottomSheetCallback(mBottomSheetBehaviorCallback);
                    Display display = getActivity().getWindowManager().getDefaultDisplay();
                    //设置高度
                    int height = display.getHeight() *2/3;
                    mBottomSheetBehavior.setPeekHeight(height);
                    parent.setBackgroundColor(Color.TRANSPARENT);
                }
            });
        }
     @Nullable
        @Override
        public View onCreateView(final LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
            View view =inflater.inflate(R.layout.fragment_bottom_sheet,container,false);
           return view;
        }

     https://blog.csdn.net/a1018875550/article/details/80954244

  • 相关阅读:
    并发编程(IO多路复用)
    411. 格雷编码
    120. 单词接龙 (BFS)
    1244. Minimum Genetic Mutation
    47.Majority Element I & II
    86. 二叉查找树迭代器
    1183. 排序数组中的单个元素
    163. 不同的二叉查找树
    428.x的n次幂
    156. 合并区间
  • 原文地址:https://www.cnblogs.com/changyiqiang/p/9353240.html
Copyright © 2011-2022 走看看