@@ -195,6 +195,8 @@ public abstract static class BottomSheetCallback {
195195
196196 int halfExpandedOffset ;
197197
198+ float halfExpandedRatio = 0.5f ;
199+
198200 int collapsedOffset ;
199201
200202 boolean hideable ;
@@ -261,6 +263,7 @@ public BottomSheetBehavior(Context context, AttributeSet attrs) {
261263 setSkipCollapsed (
262264 a .getBoolean (R .styleable .BottomSheetBehavior_Layout_behavior_skipCollapsed , false ));
263265 setSaveFlags (a .getInt (R .styleable .BottomSheetBehavior_Layout_behavior_saveFlags , SAVE_NONE ));
266+ setHalfExpandedRatio (a .getFloat (R .styleable .BottomSheetBehavior_Layout_behavior_halfExpandedRatio , 0.5f ));
264267 a .recycle ();
265268 ViewConfiguration configuration = ViewConfiguration .get (context );
266269 maximumVelocity = configuration .getScaledMaximumFlingVelocity ();
@@ -335,7 +338,7 @@ public boolean onLayoutChild(CoordinatorLayout parent, V child, int layoutDirect
335338 parentWidth = parent .getWidth ();
336339 parentHeight = parent .getHeight ();
337340 fitToContentsOffset = Math .max (0 , parentHeight - child .getHeight ());
338- halfExpandedOffset = parentHeight / 2 ;
341+ calculateHalfExpandedOffset () ;
339342 calculateCollapsedOffset ();
340343
341344 if (state == STATE_EXPANDED ) {
@@ -692,6 +695,32 @@ public final int getPeekHeight() {
692695 return peekHeightAuto ? PEEK_HEIGHT_AUTO : peekHeight ;
693696 }
694697
698+ /**
699+ * Determines the height of the BottomSheet in the {@link #STATE_HALF_EXPANDED} state. The
700+ * material guidelines recommended a value of 0.5, which results in the sheet filling half of the
701+ * parent. The height of the BottomSheet will be smaller as this ratio is decreased and taller as
702+ * it is increased. The default value is 0.5.
703+ *
704+ * @param ratio a float between 0 and 1, representing the {@link #STATE_HALF_EXPANDED} ratio.
705+ * @attr com.google.android.material.R.styleable#BottomSheetBehavior_Layout_behavior_halfExpandedRatio
706+ */
707+ public void setHalfExpandedRatio (float ratio ) {
708+
709+ if ((ratio <= 0 ) || (ratio >= 1 )) {
710+ throw new IllegalArgumentException ("ratio must be a float value between 0 and 1" );
711+ }
712+ this .halfExpandedRatio = ratio ;
713+ }
714+
715+ /**
716+ * Gets the ratio for the height of the BottomSheet in the {@link #STATE_HALF_EXPANDED} state.
717+ *
718+ * @attr com.google.android.material.R.styleable#BottomSheetBehavior_Layout_behavior_halfExpandedRatio
719+ */
720+ public float getHalfExpandedRatio () {
721+ return halfExpandedRatio ;
722+ }
723+
695724 /**
696725 * Sets whether this bottom sheet can hide when it is swiped down.
697726 *
@@ -895,6 +924,10 @@ private void calculateCollapsedOffset() {
895924 }
896925 }
897926
927+ private void calculateHalfExpandedOffset () {
928+ this .halfExpandedOffset = (int ) (parentHeight * halfExpandedRatio );
929+ }
930+
898931 private void reset () {
899932 activePointerId = ViewDragHelper .INVALID_POINTER ;
900933 if (velocityTracker != null ) {
0 commit comments