Android 12 Developer Preview is here! Try it out, and give us your feedback!

SlidingPaneLayout

public class SlidingPaneLayout
extends ViewGroup implements Openable

java.lang.Object
   ↳ android.view.View
     ↳ android.view.ViewGroup
       ↳ androidx.slidingpanelayout.widget.SlidingPaneLayout


SlidingPaneLayout provides a horizontal, multi-pane layout for use at the top level of a UI. A left (or start) pane is treated as a content list or browser, subordinate to a primary detail view for displaying content.

Child views overlap if their combined width exceeds the available width in the SlidingPaneLayout. Each of child views is expand out to fill the available width in the SlidingPaneLayout. When this occurs, the user may slide the topmost view out of the way by dragging it, and dragging back it from the very edge.

Thanks to this sliding behavior, SlidingPaneLayout may be suitable for creating layouts that can smoothly adapt across many different screen sizes, expanding out fully on larger screens and collapsing on smaller screens.

SlidingPaneLayout is distinct from a navigation drawer as described in the design guide and should not be used in the same scenarios. SlidingPaneLayout should be thought of only as a way to allow a two-pane layout normally used on larger screens to adapt to smaller screens in a natural way. The interaction patterns expressed by SlidingPaneLayout imply a physicality and direct information hierarchy between panes that does not necessarily exist in a scenario where a navigation drawer should be used instead.

Appropriate uses of SlidingPaneLayout include pairings of panes such as a contact list and subordinate interactions with those contacts, or an email thread list with the content pane displaying the contents of the selected thread. Inappropriate uses of SlidingPaneLayout include switching between disparate functions of your app, such as jumping from a social stream view to a view of your personal profile - cases such as this should use the navigation drawer pattern instead. (DrawerLayout implements this pattern.)

Like LinearLayout, SlidingPaneLayout supports the use of the layout parameter layout_weight on child views to determine how to divide leftover space after measurement is complete. It is only relevant for width. When views do not overlap weight behaves as it does in a LinearLayout.

Summary

Nested classes

class SlidingPaneLayout.LayoutParams

 

interface SlidingPaneLayout.PanelSlideListener

Listener for monitoring events about sliding panes. 

class SlidingPaneLayout.SimplePanelSlideListener

No-op stubs for SlidingPaneLayout.PanelSlideListener

Constants

int LOCK_MODE_LOCKED

The user cannot swipe between list and detail panes, though the app can open or close the detail pane programmatically.

int LOCK_MODE_LOCKED_CLOSED

The detail pane is locked in a closed position.

int LOCK_MODE_LOCKED_OPEN

The detail pane is locked in an open position.

int LOCK_MODE_UNLOCKED

User can freely swipe between list and detail panes.

Inherited constants

Inherited fields

Public constructors

SlidingPaneLayout(Context context)
SlidingPaneLayout(Context context, AttributeSet attrs)
SlidingPaneLayout(Context context, AttributeSet attrs, int defStyle)

Public methods

void addPanelSlideListener(SlidingPaneLayout.PanelSlideListener listener)

Adds the specified listener to the list of listeners that will be notified of panel slide events.

boolean canSlide()

This method is deprecated. Renamed to isSlideable() - this method is going away soon!

void close()

Close the detail view if it is currently slideable.

boolean closePane()

Close the detail view if it is currently slideable.

void computeScroll()
void draw(Canvas c)
ViewGroup.LayoutParams generateLayoutParams(AttributeSet attrs)
int getCoveredFadeColor()

This method is deprecated. This field is no longer populated by SlidingPaneLayout

final int getLockMode()

Get the lock mode used to control over the swipe behavior.

int getParallaxDistance()
int getSliderFadeColor()

This method is deprecated. This field is no longer populated by SlidingPaneLayout.

boolean isOpen()

Check if the detail view is completely open.

boolean isSlideable()

Check if the content in this layout cannot fully fit side by side and therefore the content pane can be slid back and forth.

boolean onInterceptTouchEvent(MotionEvent ev)
boolean onTouchEvent(MotionEvent ev)
void open()

Open the detail view if it is currently slideable.

boolean openPane()

Open the detail view if it is currently slideable.

void removePanelSlideListener(SlidingPaneLayout.PanelSlideListener listener)

Removes the specified listener from the list of listeners that will be notified of panel slide events.

void requestChildFocus(View child, View focused)
void setCoveredFadeColor(int color)

This method is deprecated. SlidingPaneLayout no longer uses this field.

final void setLockMode(int lockMode)

Set the lock mode that controls how the user can swipe between the panes.

void setPanelSlideListener(SlidingPaneLayout.PanelSlideListener listener)

This method is deprecated. Use addPanelSlideListener(PanelSlideListener)

void setParallaxDistance(int parallaxBy)

Set a distance to parallax the lower pane by when the upper pane is in its fully closed state.

void setShadowDrawable(Drawable d)

This method is deprecated. Renamed to setShadowDrawableLeft(Drawable) to support LTR (left to right language) and setShadowDrawableRight(Drawable) to support RTL (right to left language) during opening/closing.

void setShadowDrawableLeft(Drawable d)

Set a drawable to use as a shadow cast by the right pane onto the left pane during opening/closing.

void setShadowDrawableRight(Drawable d)

Set a drawable to use as a shadow cast by the left pane onto the right pane during opening/closing to support right to left language.

void setShadowResource(int resId)

This method is deprecated. Renamed to setShadowResourceLeft(int) to support LTR (left to right language) and setShadowResourceRight(int) to support RTL (right to left language) during opening/closing.

void setShadowResourceLeft(int resId)

Set a drawable to use as a shadow cast by the right pane onto the left pane during opening/closing.

void setShadowResourceRight(int resId)

Set a drawable to use as a shadow cast by the left pane onto the right pane during opening/closing to support right to left language.

void setSliderFadeColor(int color)

This method is deprecated. SlidingPaneLayout no longer uses this field.

void smoothSlideClosed()

This method is deprecated. Renamed to closePane() - this method is going away soon!

void smoothSlideOpen()

This method is deprecated. Renamed to openPane() - this method is going away soon!

Protected methods

boolean canScroll(View v, boolean checkV, int dx, int x, int y)

Tests scrollability within child views of v given a delta of dx.

boolean checkLayoutParams(ViewGroup.LayoutParams p)
boolean drawChild(Canvas canvas, View child, long drawingTime)
ViewGroup.LayoutParams generateDefaultLayoutParams()
ViewGroup.LayoutParams generateLayoutParams(ViewGroup.LayoutParams p)
void onAttachedToWindow()
void onDetachedFromWindow()
void onLayout(boolean changed, int l, int t, int r, int b)
void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
void onRestoreInstanceState(Parcelable state)
Parcelable onSaveInstanceState()
void onSizeChanged(int w, int h, int oldw, int oldh)

Inherited methods