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 types |
|---|
public class SlidingPaneLayout.LayoutParams extends ViewGroup.MarginLayoutParams |
public interface SlidingPaneLayout.PanelSlideListenerListener for monitoring events about sliding panes. |
public class SlidingPaneLayout.SimplePanelSlideListener implements SlidingPaneLayout.PanelSlideListenerNo-op stubs for |
Constants |
|
|---|---|
static final int |
LOCK_MODE_LOCKED = 3The user cannot swipe between list and detail panes, though the app can open or close the detail pane programmatically. |
static final int |
The detail pane is locked in a closed position. |
static final int |
The detail pane is locked in an open position. |
static final int |
User can freely swipe between list and detail panes. |
Public constructors |
|---|
SlidingPaneLayout(@NonNull Context context) |
SlidingPaneLayout(@NonNull Context context, @Nullable AttributeSet attrs) |
SlidingPaneLayout( |
Public methods |
|
|---|---|
void |
Adds the specified listener to the list of listeners that will be notified of panel slide events. |
void |
addView( |
boolean |
This method is deprecated. Renamed to |
void |
close()Close the detail view if it is currently slideable. |
boolean |
Close the detail view if it is currently slideable. |
void |
|
void |
|
ViewGroup.LayoutParams |
generateLayoutParams(AttributeSet attrs) |
@ColorInt int |
This method is deprecated. This field is no longer populated by SlidingPaneLayout |
final int |
Get the lock mode used to control over the swipe behavior. |
@Px int |
|
@ColorInt int |
This method is deprecated. This field is no longer populated by SlidingPaneLayout. |
boolean |
isOpen()Check if the detail view is completely open. |
boolean |
Check if both the list and detail view panes in this layout can fully fit side-by-side. |
boolean |
|
boolean |
|
void |
open()Open the detail view if it is currently slideable. |
boolean |
openPane()Open the detail view if it is currently slideable. |
void |
Removes the specified listener from the list of listeners that will be notified of panel slide events. |
void |
removeView(@NonNull View view) |
void |
requestChildFocus(View child, View focused) |
void |
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 |
This method is deprecated. |
void |
setParallaxDistance(@Px int parallaxBy)Set a distance to parallax the lower pane by when the upper pane is in its fully closed state. |
void |
This method is deprecated. Renamed to |
void |
Set a drawable to use as a shadow cast by the right pane onto the left pane during opening/closing. |
void |
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 |
This method is deprecated. Renamed to |
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 |
This method is deprecated. SlidingPaneLayout no longer uses this field. |
void |
This method is deprecated. Renamed to |
void |
This method is deprecated. Renamed to |
Protected methods |
|
|---|---|
boolean |
Tests scrollability within child views of v given a delta of dx. |
boolean |
|
boolean |
|
ViewGroup.LayoutParams |
|
ViewGroup.LayoutParams |
|
void |
|
void |
|
void |
onLayout(boolean changed, int l, int t, int r, int b) |
void |
onMeasure(int widthMeasureSpec, int heightMeasureSpec) |
void |
onRestoreInstanceState(Parcelable state) |
Parcelable |
|
void |
onSizeChanged(int w, int h, int oldw, int oldh) |
Inherited Constants |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Inherited methods |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Constants
LOCK_MODE_LOCKED
public static final int LOCK_MODE_LOCKED = 3
The user cannot swipe between list and detail panes, though the app can open or close the detail pane programmatically.
LOCK_MODE_LOCKED_CLOSED
public static final int LOCK_MODE_LOCKED_CLOSED = 2
The detail pane is locked in a closed position. The user cannot swipe to open the detail pane, but the app can open the detail pane programmatically.
LOCK_MODE_LOCKED_OPEN
public static final int LOCK_MODE_LOCKED_OPEN = 1
The detail pane is locked in an open position. The user cannot swipe to close the detail pane, but the app can close the detail pane programmatically.
LOCK_MODE_UNLOCKED
public static final int LOCK_MODE_UNLOCKED = 0
User can freely swipe between list and detail panes.
Public constructors
SlidingPaneLayout
public SlidingPaneLayout(@NonNull Context context, @Nullable AttributeSet attrs)
SlidingPaneLayout
public SlidingPaneLayout(
@NonNull Context context,
@Nullable AttributeSet attrs,
int defStyle
)
Public methods
addPanelSlideListener
public void addPanelSlideListener(
@NonNull SlidingPaneLayout.PanelSlideListener listener
)
Adds the specified listener to the list of listeners that will be notified of panel slide events.
| Parameters | |
|---|---|
@NonNull SlidingPaneLayout.PanelSlideListener listener |
Listener to notify when panel slide events occur. |
| See also | |
|---|---|
removePanelSlideListener |
addView
public void addView(
@NonNull View child,
int index,
@Nullable ViewGroup.LayoutParams params
)
public boolean canSlide()| Returns | |
|---|---|
boolean |
true if content in this layout can be slid open and closed |
close
public void close()
Close the detail view if it is currently slideable. If first layout has already completed this will animate.
closePane
public boolean closePane()
Close the detail view if it is currently slideable. If first layout has already completed this will animate.
| Returns | |
|---|---|
boolean |
true if the pane was slideable and is now closed/in the process of closing |
public @ColorInt intgetCoveredFadeColor()
| Returns | |
|---|---|
@ColorInt int |
The ARGB-packed color value used to fade the fixed pane |
getLockMode
public final int getLockMode()
Get the lock mode used to control over the swipe behavior.
| See also | |
|---|---|
setLockMode |
getParallaxDistance
public @Px int getParallaxDistance()
| Returns | |
|---|---|
@Px int |
The distance the lower pane will parallax by when the upper pane is fully closed. |
| See also | |
|---|---|
setParallaxDistance |
public @ColorInt intgetSliderFadeColor()
| Returns | |
|---|---|
@ColorInt int |
The ARGB-packed color value used to fade the sliding pane |
isOpen
public boolean isOpen()
Check if the detail view is completely open. It can be open either because the slider itself is open revealing the detail view, or if all content fits without sliding.
| Returns | |
|---|---|
boolean |
true if the detail view is completely open |
isSlideable
public boolean isSlideable()
Check if both the list and detail view panes in this layout can fully fit side-by-side. If not, the content pane has the capability to slide back and forth. Note that the lock mode is not taken into account in this method. This method is typically used to determine whether the layout is showing two-pane or single-pane.
| Returns | |
|---|---|
boolean |
true if both panes cannot fit side-by-side, and detail pane in this layout has the capability to slide back and forth. |
open
public void open()
Open the detail view if it is currently slideable. If first layout has already completed this will animate.
openPane
public boolean openPane()
Open the detail view if it is currently slideable. If first layout has already completed this will animate.
| Returns | |
|---|---|
boolean |
true if the pane was slideable and is now open/in the process of opening |
removePanelSlideListener
public void removePanelSlideListener(
@NonNull SlidingPaneLayout.PanelSlideListener listener
)
Removes the specified listener from the list of listeners that will be notified of panel slide events.
| Parameters | |
|---|---|
@NonNull SlidingPaneLayout.PanelSlideListener listener |
Listener to remove from being notified of panel slide events |
| See also | |
|---|---|
addPanelSlideListener |
public voidsetCoveredFadeColor(@ColorInt int color)
Set the color used to fade the pane covered by the sliding pane out when the pane will become fully covered in the closed state.
| Parameters | |
|---|---|
@ColorInt int color |
An ARGB-packed color value |
setLockMode
public final void setLockMode(int lockMode)
Set the lock mode that controls how the user can swipe between the panes.
| Parameters | |
|---|---|
int lockMode |
The new lock mode for the detail pane. |
public voidsetPanelSlideListener(
@Nullable SlidingPaneLayout.PanelSlideListener listener
)
Set a listener to be notified of panel slide events. Note that this method is deprecated and you should use addPanelSlideListener to add a listener and removePanelSlideListener to remove a registered listener.
| Parameters | |
|---|---|
@Nullable SlidingPaneLayout.PanelSlideListener listener |
Listener to notify when drawer events occur |
setParallaxDistance
public void setParallaxDistance(@Px int parallaxBy)
Set a distance to parallax the lower pane by when the upper pane is in its fully closed state. The lower pane will scroll between this position and its fully open state.
| Parameters | |
|---|---|
@Px int parallaxBy |
Distance to parallax by in pixels |
setShadowDrawableLeft
public void setShadowDrawableLeft(@Nullable Drawable d)
Set a drawable to use as a shadow cast by the right pane onto the left pane during opening/closing.
setShadowDrawableRight
public void setShadowDrawableRight(@Nullable 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.
public voidsetShadowResource(@DrawableRes int resId)
Set a drawable to use as a shadow cast by the right pane onto the left pane during opening/closing.
| Parameters | |
|---|---|
@DrawableRes int resId |
Resource ID of a drawable to use |
setShadowResourceLeft
public void setShadowResourceLeft(int resId)
Set a drawable to use as a shadow cast by the right pane onto the left pane during opening/closing.
| Parameters | |
|---|---|
int resId |
Resource ID of a drawable to use |
setShadowResourceRight
public 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.
| Parameters | |
|---|---|
int resId |
Resource ID of a drawable to use |
public voidsetSliderFadeColor(@ColorInt int color)
Set the color used to fade the sliding pane out when it is slid most of the way offscreen.
| Parameters | |
|---|---|
@ColorInt int color |
An ARGB-packed color value |
Protected methods
canScroll
protected boolean canScroll(View v, boolean checkV, int dx, int x, int y)
Tests scrollability within child views of v given a delta of dx.
| Parameters | |
|---|---|
View v |
View to test for horizontal scrollability |
boolean checkV |
Whether the view v passed should itself be checked for scrollability (true), or just its children (false). |
int dx |
Delta scrolled in pixels |
int x |
X coordinate of the active touch point |
int y |
Y coordinate of the active touch point |
| Returns | |
|---|---|
boolean |
true if child views of v can be scrolled by delta of dx. |
generateLayoutParams
protected ViewGroup.LayoutParams generateLayoutParams(ViewGroup.LayoutParams p)