2016-05-13 12 views
1

私は方法を知っていますchange the height of a Bottom Sheet。 ボトムシートの高さを上げることに問題はありません。しかし、私は次のコードでその高さを減らすことはできません。ボトムシートの高さを小さくする

bottomSheetBehavior.setPeekHeight(peekHeight); // peekHeight < previous height 
bottomSheetBehavior.setState(STATE_COLLAPSED); 

誰でも同じ問題が発生しましたか?

+0

一度設定した後にピーク高さを変更すると、適用されません。 –

+0

peekHeightを設定する前にBottomSheetBehavior.from(bottomSheet)を使用しようとしましたか?あなたはあなたのbottomSheetをパラメタとして渡して、上記で使用した行を追加することができます –

答えて

3

私は同じことをしようとしていますが、私はそのような問題はありません。私は簡単に私のBottomSheetDialogFragmentの高さを増減することができました。

private BottomSheetBehavior.BottomSheetCallback bottomSheetCallback = new BottomSheetBehavior.BottomSheetCallback() { 
     @Override 
     public void onStateChanged(@NonNull View bottomSheet, int newState) { 
      if (newState == BottomSheetBehavior.STATE_HIDDEN) { 
       dismiss(); 
      } 
     } 

     @Override 
     public void onSlide(@NonNull View bottomSheet, float slideOffset) { 
     } 
    }; 

    public static BottomSheetFragment newInstance() { 
     return new BottomSheetFragment(); 
    } 

    @Override 
    public void setupDialog(Dialog dialog, int style) { 
     super.setupDialog(dialog, style); 
     View contentView = View.inflate(getContext(), R.layout.bottom_sheet_dialog_content_view, null); 
     dialog.setContentView(contentView); 
     CoordinatorLayout.LayoutParams layoutParams = ((CoordinatorLayout.LayoutParams) ((View) contentView.getParent()).getLayoutParams()); 
     CoordinatorLayout.Behavior behavior = layoutParams.getBehavior(); 
     if (behavior != null && behavior instanceof BottomSheetBehavior) { 
      ((BottomSheetBehavior) behavior).setBottomSheetCallback(bottomSheetCallback); 
      ((BottomSheetBehavior) behavior).setPeekHeight(getResources().getDimensionPixelSize(R.dimen.bottom_sheet_height)/4); 
     } 

     initRecyclerView(contentView); 
    } 
関連する問題