SideSheetBehavior
public class SideSheetBehavior
extends Behavior<V extends View>
java.lang.Object | ||
↳ | androidx.coordinatorlayout.widget.CoordinatorLayout.Behavior<V extends android.view.View> | |
↳ | com.google.android.material.sidesheet.SideSheetBehavior<V extends android.view.View> |
An interaction behavior plugin for a child view of CoordinatorLayout
to make it work as a side sheet.
For more information, see the component developer guidance and design guidelines.
Summary
Nested classes | |
---|---|
class | SideSheetBehavior.SavedState State persisted across instances |
XML attributes | |
---|---|
SideSheetBehavior_Layout_behavior_draggable |
Constants | |
---|---|
int | EDGE_LEFT The sheet is based on the left edge of the screen; it slides from the left edge towards the right. |
int | EDGE_RIGHT The sheet is based on the right edge of the screen; it slides from the right edge towards the left. |
int | STATE_DRAGGING The sheet is dragging. |
int | STATE_EXPANDED The sheet is expanded. |
int | STATE_HIDDEN The sheet is hidden. |
int | STATE_SETTLING The sheet is settling. |
Public constructors | |
---|---|
SideSheetBehavior() | |
SideSheetBehavior(Context context, AttributeSet attrs) |
Public methods | |
---|---|
void | addCallback(SideSheetCallback callback) Adds a callback to be notified of side sheet events. |
void | cancelBackProgress() |
void | expand() Expand the sheet by setting the side sheet state to |
static <V extends View> SideSheetBehavior<V> | from(V view) A utility function to get the |
View | getCoplanarSiblingView() Returns the sibling view that is used for coplanar sheet expansion. |
int | getExpandedOffset() Returns the sheet's offset from the inner edge when expanded. |
float | getHideFriction() Gets the friction coefficient to hide the sheet, or set it to the next closest expanded state. |
int | getState() Gets the current state of the sheet. |
void | handleBackInvoked() |
void | hide() Hide the sheet by setting the sheet state to |
boolean | isDraggable() |
void | onAttachedToLayoutParams(CoordinatorLayout.LayoutParams layoutParams) |
void | onDetachedFromLayoutParams() |
boolean | onInterceptTouchEvent(CoordinatorLayout parent, V child, MotionEvent event) |
boolean | onLayoutChild(CoordinatorLayout parent, V child, int layoutDirection) |
boolean | onMeasureChild(CoordinatorLayout parent, V child, int parentWidthMeasureSpec, int widthUsed, int parentHeightMeasureSpec, int heightUsed) |
void | onRestoreInstanceState(CoordinatorLayout parent, V child, Parcelable state) |
Parcelable | onSaveInstanceState(CoordinatorLayout parent, V child) |
boolean | onTouchEvent(CoordinatorLayout parent, V child, MotionEvent event) |
void | removeCallback(SideSheetCallback callback) Removes a previously added callback. |
void | setCoplanarSiblingView(View coplanarSiblingView) Set the sibling view to use for coplanar sheet expansion. |
void | setCoplanarSiblingViewId(int coplanarSiblingViewId) Set the sibling id to use for coplanar sheet expansion. |
void | setDraggable(boolean draggable) Sets whether this sheet is can be hidden/expanded by dragging. |
void | setHideFriction(float hideFriction) Sets the friction coefficient to hide the sheet, or set it to the next closest expanded state. |
void | setState(int state) Sets the state of the sheet. |
void | startBackProgress(BackEventCompat backEvent) |
void | updateBackProgress(BackEventCompat backEvent) |
Inherited methods | |
---|---|
XML attributes
SideSheetBehavior_Layout_behavior_draggable
Related methods:
Constants
EDGE_LEFT
public static final int EDGE_LEFT
The sheet is based on the left edge of the screen; it slides from the left edge towards the right.
Constant Value: 1 (0x00000001)
EDGE_RIGHT
public static final int EDGE_RIGHT
The sheet is based on the right edge of the screen; it slides from the right edge towards the left.
Constant Value: 0 (0x00000000)
STATE_DRAGGING
public static final int STATE_DRAGGING
The sheet is dragging.
Constant Value: 1 (0x00000001)
STATE_EXPANDED
public static final int STATE_EXPANDED
The sheet is expanded.
Constant Value: 3 (0x00000003)
STATE_HIDDEN
public static final int STATE_HIDDEN
The sheet is hidden.
Constant Value: 5 (0x00000005)
STATE_SETTLING
public static final int STATE_SETTLING
The sheet is settling.
Constant Value: 2 (0x00000002)
Public constructors
SideSheetBehavior
public SideSheetBehavior ()
SideSheetBehavior
public SideSheetBehavior (Context context, AttributeSet attrs)
Parameters | |
---|---|
context | Context |
attrs | AttributeSet |
Public methods
addCallback
public void addCallback (SideSheetCallback callback)
Adds a callback to be notified of side sheet events.
Parameters | |
---|---|
callback | SideSheetCallback : The callback to notify when side sheet events occur. |
cancelBackProgress
public void cancelBackProgress ()
expand
public void expand ()
Expand the sheet by setting the side sheet state to ERROR(/Sheet#STATE_EXPANDED)
. This is a convenience method for setState(int)
.
from
public static SideSheetBehavior<V> from (V view)
A utility function to get the SideSheetBehavior
associated with the view
.
Parameters | |
---|---|
view | V : The View with SideSheetBehavior . |
Returns | |
---|---|
SideSheetBehavior<V> | The SideSheetBehavior associated with the view . |
getCoplanarSiblingView
public View getCoplanarSiblingView ()
Returns the sibling view that is used for coplanar sheet expansion.
Returns | |
---|---|
View |
getExpandedOffset
public int getExpandedOffset ()
Returns the sheet's offset from the inner edge when expanded. It will calculate the offset based on the width of the content.
Returns | |
---|---|
int |
getHideFriction
public float getHideFriction ()
Gets the friction coefficient to hide the sheet, or set it to the next closest expanded state.
Returns | |
---|---|
float | The friction coefficient that determines the swipe velocity needed to hide or set the sheet to the closest expanded state. |
getState
public int getState ()
Gets the current state of the sheet.
Returns | |
---|---|
int | One of STATE_EXPANDED , STATE_DRAGGING , STATE_SETTLING , or STATE_HIDDEN . |
handleBackInvoked
public void handleBackInvoked ()
hide
public void hide ()
Hide the sheet by setting the sheet state to ERROR(/Sheet#STATE_HIDDEN)
. This is a convenience method for setState(int)
.
isDraggable
public boolean isDraggable ()
Returns | |
---|---|
boolean |
onAttachedToLayoutParams
public void onAttachedToLayoutParams (CoordinatorLayout.LayoutParams layoutParams)
Parameters | |
---|---|
layoutParams | CoordinatorLayout.LayoutParams |
onDetachedFromLayoutParams
public void onDetachedFromLayoutParams ()
onInterceptTouchEvent
public boolean onInterceptTouchEvent (CoordinatorLayout parent, V child, MotionEvent event)
Parameters | |
---|---|
parent | CoordinatorLayout |
child | V |
event | MotionEvent |
Returns | |
---|---|
boolean |
onLayoutChild
public boolean onLayoutChild (CoordinatorLayout parent, V child, int layoutDirection)
Parameters | |
---|---|
parent | CoordinatorLayout |
child | V |
layoutDirection | int |
Returns | |
---|---|
boolean |
onMeasureChild
public boolean onMeasureChild (CoordinatorLayout parent, V child, int parentWidthMeasureSpec, int widthUsed, int parentHeightMeasureSpec, int heightUsed)
Parameters | |
---|---|
parent | CoordinatorLayout |
child | V |
parentWidthMeasureSpec | int |
widthUsed | int |
parentHeightMeasureSpec | int |
heightUsed | int |
Returns | |
---|---|
boolean |
onRestoreInstanceState
public void onRestoreInstanceState (CoordinatorLayout parent, V child, Parcelable state)
Parameters | |
---|---|
parent | CoordinatorLayout |
child | V |
state | Parcelable |
onSaveInstanceState
public Parcelable onSaveInstanceState (CoordinatorLayout parent, V child)
Parameters | |
---|---|
parent | CoordinatorLayout |
child | V |
Returns | |
---|---|
Parcelable |
onTouchEvent
public boolean onTouchEvent (CoordinatorLayout parent, V child, MotionEvent event)
Parameters | |
---|---|
parent | CoordinatorLayout |
child | V |
event | MotionEvent |
Returns | |
---|---|
boolean |
removeCallback
public void removeCallback (SideSheetCallback callback)
Removes a previously added callback.
Parameters | |
---|---|
callback | SideSheetCallback : The callback to remove. |
setCoplanarSiblingView
public void setCoplanarSiblingView (View coplanarSiblingView)
Set the sibling view to use for coplanar sheet expansion. If a coplanar sibling has previously been set either by this method or via setCoplanarSiblingViewId(int)
, that reference will be cleared in favor of this new coplanar sibling reference.
Parameters | |
---|---|
coplanarSiblingView | View : the sibling view to squash during coplanar expansion |
setCoplanarSiblingViewId
public void setCoplanarSiblingViewId (int coplanarSiblingViewId)
Set the sibling id to use for coplanar sheet expansion. If a coplanar sibling has previously been set either by this method or via setCoplanarSiblingView(View)
, that View reference will be cleared in favor of this new coplanar sibling reference.
Parameters | |
---|---|
coplanarSiblingViewId | int : the id of the coplanar sibling |
setDraggable
public void setDraggable (boolean draggable)
Sets whether this sheet is can be hidden/expanded by dragging. Note: When disabling dragging, an app will require to implement a custom way to expand/collapse the sheet
Related XML Attributes:
Parameters | |
---|---|
draggable | boolean : false to prevent dragging the sheet to collapse and expand |
setHideFriction
public void setHideFriction (float hideFriction)
Sets the friction coefficient to hide the sheet, or set it to the next closest expanded state.
Parameters | |
---|---|
hideFriction | float : The friction coefficient that determines the swipe velocity needed to hide or set the sheet to the closest expanded state. |
setState
public void setState (int state)
Sets the state of the sheet. The sheet will transition to that state with animation.
Parameters | |
---|---|
state | int : One of STATE_EXPANDED or STATE_HIDDEN . |
startBackProgress
public void startBackProgress (BackEventCompat backEvent)
Parameters | |
---|---|
backEvent | BackEventCompat |
updateBackProgress
public void updateBackProgress (BackEventCompat backEvent)
Parameters | |
---|---|
backEvent | BackEventCompat |
Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2025-02-10 UTC.