SlidingPaneLayout
class SlidingPaneLayout : ViewGroup, Openable
kotlin.Any | |||
↳ | 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 |
---|
interface SlidingPaneLayout.PanelSlideListener Listener for monitoring events about sliding panes. |
No-op stubs for |
Constants |
|
---|---|
const 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. |
const Int |
The detail pane is locked in a closed position. |
const Int |
The detail pane is locked in an open position. |
const Int |
User can freely swipe between list and detail panes. |
Public constructors |
---|
SlidingPaneLayout(context: Context) |
SlidingPaneLayout(context: Context, attrs: AttributeSet?) |
SlidingPaneLayout(context: Context, attrs: AttributeSet?, defStyle: Int) |
Public functions |
|
---|---|
Unit |
Adds the specified listener to the list of listeners that will be notified of panel slide events. |
Unit |
addView(child: View, index: Int, params: ViewGroup.LayoutParams?) |
Boolean |
This function is deprecated. Renamed to |
Unit |
close() Close the detail view if it is currently slideable. |
Boolean |
Close the detail view if it is currently slideable. |
Unit |
|
Unit |
|
ViewGroup.LayoutParams! |
generateLayoutParams(attrs: AttributeSet!) |
@ColorInt Int |
This function is deprecated. This field is no longer populated by SlidingPaneLayout |
Int |
Get the lock mode used to control over the swipe behavior. |
@Px Int |
|
@ColorInt Int |
This function 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 |
onTouchEvent(ev: MotionEvent!) |
Unit |
open() Open the detail view if it is currently slideable. |
Boolean |
openPane() Open the detail view if it is currently slideable. |
Unit |
Removes the specified listener from the list of listeners that will be notified of panel slide events. |
Unit |
removeView(view: View) |
Unit |
requestChildFocus(child: View!, focused: View!) |
Unit |
This function is deprecated. SlidingPaneLayout no longer uses this field. |
Unit |
setLockMode(lockMode: Int) Set the lock mode that controls how the user can swipe between the panes. |
Unit |
This function is deprecated. |
Unit |
setParallaxDistance(parallaxBy: @Px Int) Set a distance to parallax the lower pane by when the upper pane is in its fully closed state. |
Unit |
This function is deprecated. Renamed to |
Unit |
Set a drawable to use as a shadow cast by the right pane onto the left pane during opening/closing. |
Unit |
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. |
Unit |
This function is deprecated. Renamed to |
Unit |
setShadowResourceLeft(resId: Int) Set a drawable to use as a shadow cast by the right pane onto the left pane during opening/closing. |
Unit |
setShadowResourceRight(resId: Int) 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. |
Unit |
This function is deprecated. SlidingPaneLayout no longer uses this field. |
Unit |
This function is deprecated. Renamed to |
Unit |
This function is deprecated. Renamed to |
Protected functions |
|
---|---|
Boolean |
Tests scrollability within child views of v given a delta of dx. |
Boolean |
|
Boolean |
|
ViewGroup.LayoutParams! |
|
ViewGroup.LayoutParams! |
|
Unit |
|
Unit |
|
Unit |
|
Unit |
|
Unit |
onRestoreInstanceState(state: Parcelable!) |
Parcelable! |
|
Unit |
onSizeChanged(w: Int, h: Int, oldw: Int, oldh: Int) |
Inherited Constants |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Constants
LOCK_MODE_LOCKED
const val LOCK_MODE_LOCKED = 3: Int
The user cannot swipe between list and detail panes, though the app can open or close the detail pane programmatically.
LOCK_MODE_LOCKED_CLOSED
const val LOCK_MODE_LOCKED_CLOSED = 2: Int
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
const val LOCK_MODE_LOCKED_OPEN = 1: Int
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
const val LOCK_MODE_UNLOCKED = 0: Int
User can freely swipe between list and detail panes.
Public constructors
SlidingPaneLayout
SlidingPaneLayout(context: Context, attrs: AttributeSet?, defStyle: Int)
Public functions
addPanelSlideListener
fun addPanelSlideListener(listener: SlidingPaneLayout.PanelSlideListener): Unit
Adds the specified listener to the list of listeners that will be notified of panel slide events.
Parameters | |
---|---|
listener: SlidingPaneLayout.PanelSlideListener |
Listener to notify when panel slide events occur. |
See also | |
---|---|
removePanelSlideListener |
close
fun close(): Unit
Close the detail view if it is currently slideable. If first layout has already completed this will animate.
closePane
fun closePane(): Boolean
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 |
getLockMode
fun getLockMode(): Int
Get the lock mode used to control over the swipe behavior.
See also | |
---|---|
setLockMode |
isOpen
fun isOpen(): Boolean
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
fun isSlideable(): Boolean
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
fun open(): Unit
Open the detail view if it is currently slideable. If first layout has already completed this will animate.
openPane
fun openPane(): Boolean
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
fun removePanelSlideListener(
listener: SlidingPaneLayout.PanelSlideListener
): Unit
Removes the specified listener from the list of listeners that will be notified of panel slide events.
Parameters | |
---|---|
listener: SlidingPaneLayout.PanelSlideListener |
Listener to remove from being notified of panel slide events |
See also | |
---|---|
addPanelSlideListener |
funsetCoveredFadeColor(color: @ColorInt Int): Unit
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.
setLockMode
fun setLockMode(lockMode: Int): Unit
Set the lock mode that controls how the user can swipe between the panes.
Parameters | |
---|---|
lockMode: Int |
The new lock mode for the detail pane. |
funsetPanelSlideListener(listener: SlidingPaneLayout.PanelSlideListener?): Unit
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 | |
---|---|
listener: SlidingPaneLayout.PanelSlideListener? |
Listener to notify when drawer events occur |
setParallaxDistance
fun setParallaxDistance(parallaxBy: @Px Int): Unit
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.
setShadowDrawableLeft
fun setShadowDrawableLeft(d: Drawable?): Unit
Set a drawable to use as a shadow cast by the right pane onto the left pane during opening/closing.
Parameters | |
---|---|
d: Drawable? |
drawable to use as a shadow |
setShadowDrawableRight
fun setShadowDrawableRight(d: Drawable?): Unit
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 | |
---|---|
d: Drawable? |
drawable to use as a shadow |
funsetShadowResource(resId: @DrawableRes Int): Unit
Set a drawable to use as a shadow cast by the right pane onto the left pane during opening/closing.
Parameters | |
---|---|
resId: @DrawableRes Int |
Resource ID of a drawable to use |
setShadowResourceLeft
fun setShadowResourceLeft(resId: Int): Unit
Set a drawable to use as a shadow cast by the right pane onto the left pane during opening/closing.
Parameters | |
---|---|
resId: Int |
Resource ID of a drawable to use |
setShadowResourceRight
fun setShadowResourceRight(resId: Int): Unit
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 | |
---|---|
resId: Int |
Resource ID of a drawable to use |
funsetSliderFadeColor(color: @ColorInt Int): Unit
Set the color used to fade the sliding pane out when it is slid most of the way offscreen.
Protected functions
canScroll
protected fun canScroll(v: View!, checkV: Boolean, dx: Int, x: Int, y: Int): Boolean
Tests scrollability within child views of v given a delta of dx.
Parameters | |
---|---|
v: View! |
View to test for horizontal scrollability |
checkV: Boolean |
Whether the view v passed should itself be checked for scrollability (true), or just its children (false). |
dx: Int |
Delta scrolled in pixels |
x: Int |
X coordinate of the active touch point |
y: Int |
Y coordinate of the active touch point |
Returns | |
---|---|
Boolean |
true if child views of v can be scrolled by delta of dx. |
generateLayoutParams
protected fun generateLayoutParams(p: ViewGroup.LayoutParams!): ViewGroup.LayoutParams!