The Android Developer Challenge is back! Submit your idea before December 2.

SlidingPaneLayout

open class SlidingPaneLayout : ViewGroup
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 first) pane is treated as a content list or browser, subordinate to a primary detail view for displaying content.

Child views may overlap if their combined width exceeds the available width in the SlidingPaneLayout. When this occurs the user may slide the topmost view out of the way by dragging it, or by navigating in the direction of the overlapped view using a keyboard. If the content of the dragged child view is itself horizontally scrollable, the user may grab it by 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.

When views do overlap, weight on a slideable pane indicates that the pane should be sized to fill all available space in the closed state. Weight on a pane that becomes covered indicates that the pane should be sized to fill all available space except a small minimum strip that the user may use to grab the slideable view and pull it back over into a closed state.

Summary

Nested classes

open

abstract

Listener for monitoring events about sliding panes.

open

No-op stubs for PanelSlideListener.

Public constructors

<init>(@NonNull context: Context)

<init>(@NonNull context: Context, @Nullable attrs: AttributeSet?)

<init>(@NonNull context: Context, @Nullable attrs: AttributeSet?, defStyle: Int)

Public methods

open Boolean

open Boolean

Close the sliding pane if it is currently slideable.

open Unit

open Unit
draw(c: Canvas!)

open LayoutParams!

open Int

open Int

open Int

open Boolean

Check if the layout is completely open.

open Boolean

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

open Boolean

open Boolean

open Boolean

Open the sliding pane if it is currently slideable.

open Unit
requestChildFocus(child: View!, focused: View!)

open 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.

open Unit

open Unit
setParallaxDistance(@Px parallaxBy: Int)

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

open Unit

open Unit

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

open 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.

open Unit
setShadowResource(@DrawableRes resId: Int)

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

open Unit

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

open 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.

open Unit

Set the color used to fade the sliding pane out when it is slid most of the way offscreen.

open Unit

open Unit

Protected methods

open Boolean
canScroll(v: View!, checkV: Boolean, dx: Int, x: Int, y: Int)

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

open Boolean

open Boolean
drawChild(canvas: Canvas!, child: View!, drawingTime: Long)

open LayoutParams!

open LayoutParams!

open Unit

open Unit

open Unit
onLayout(changed: Boolean, l: Int, t: Int, r: Int, b: Int)

open Unit
onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int)

open Unit

open Parcelable!

open Unit
onSizeChanged(w: Int, h: Int, oldw: Int, oldh: Int)

Public constructors

<init>

SlidingPaneLayout(@NonNull context: Context)

<init>

SlidingPaneLayout(@NonNull context: Context, @Nullable attrs: AttributeSet?)

<init>

SlidingPaneLayout(@NonNull context: Context, @Nullable attrs: AttributeSet?, defStyle: Int)

Public methods

canSlide

open fun canSlide(): Boolean

Deprecated: Renamed to isSlideable() - this method is going away soon!

Return
Boolean: true if content in this layout can be slid open and closed

closePane

open fun closePane(): Boolean

Close the sliding pane if it is currently slideable. If first layout has already completed this will animate.

Return
Boolean: true if the pane was slideable and is now closed/in the process of closing

computeScroll

open fun computeScroll(): Unit

draw

open fun draw(c: Canvas!): Unit

generateLayoutParams

open fun generateLayoutParams(attrs: AttributeSet!): LayoutParams!

getCoveredFadeColor

open fun getCoveredFadeColor(): Int
Return
Int: The ARGB-packed color value used to fade the fixed pane

getParallaxDistance

@Px open fun getParallaxDistance(): Int
Return
Int: The distance the lower pane will parallax by when the upper pane is fully closed.

getSliderFadeColor

open fun getSliderFadeColor(): Int
Return
Int: The ARGB-packed color value used to fade the sliding pane

isOpen

open fun isOpen(): Boolean

Check if the layout is completely open. It can be open either because the slider itself is open revealing the left pane, or if all content fits without sliding.

Return
Boolean: true if sliding panels are completely open

isSlideable

open fun isSlideable(): Boolean

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

Return
Boolean: true if content in this layout can be slid open and closed

onInterceptTouchEvent

open fun onInterceptTouchEvent(ev: MotionEvent!): Boolean

onTouchEvent

open fun onTouchEvent(ev: MotionEvent!): Boolean

openPane

open fun openPane(): Boolean

Open the sliding pane if it is currently slideable. If first layout has already completed this will animate.

Return
Boolean: true if the pane was slideable and is now open/in the process of opening

requestChildFocus

open fun requestChildFocus(child: View!, focused: View!): Unit

setCoveredFadeColor

open fun setCoveredFadeColor(color: 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.

Parameters
color Int: An ARGB-packed color value

setPanelSlideListener

open fun setPanelSlideListener(@Nullable listener: SlidingPaneLayout.PanelSlideListener?): Unit

setParallaxDistance

open fun setParallaxDistance(@Px parallaxBy: 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.

Parameters
parallaxBy Int: Distance to parallax by in pixels

setShadowDrawable

open fun setShadowDrawable(d: Drawable!): Unit

Deprecated: Renamed to setShadowDrawableLeft(Drawable d) to support LTR (left to right language) and setShadowDrawableRight(Drawable d) to support RTL (right to left language) during opening/closing.

Parameters
d Drawable!: drawable to use as a shadow

setShadowDrawableLeft

open fun setShadowDrawableLeft(@Nullable 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

open fun setShadowDrawableRight(@Nullable 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

setShadowResource

open fun setShadowResource(@DrawableRes resId: Int): Unit

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.

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

setShadowResourceLeft

open 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

open 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

setSliderFadeColor

open fun setSliderFadeColor(color: Int): Unit

Set the color used to fade the sliding pane out when it is slid most of the way offscreen.

Parameters
color Int: An ARGB-packed color value

smoothSlideClosed

open fun smoothSlideClosed(): Unit

Deprecated: Renamed to closePane() - this method is going away soon!

smoothSlideOpen

open fun smoothSlideOpen(): Unit

Deprecated: Renamed to openPane() - this method is going away soon!

Protected methods

canScroll

protected open 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 View!: Whether the view v passed should itself be checked for scrollability (true), or just its children (false).
dx View!: Delta scrolled in pixels
x View!: X coordinate of the active touch point
y View!: Y coordinate of the active touch point
Return
Boolean: true if child views of v can be scrolled by delta of dx.

checkLayoutParams

protected open fun checkLayoutParams(p: LayoutParams!): Boolean

drawChild

protected open fun drawChild(canvas: Canvas!, child: View!, drawingTime: Long): Boolean

generateDefaultLayoutParams

protected open fun generateDefaultLayoutParams(): LayoutParams!

generateLayoutParams

protected open fun generateLayoutParams(p: LayoutParams!): LayoutParams!

onAttachedToWindow

protected open fun onAttachedToWindow(): Unit

onDetachedFromWindow

protected open fun onDetachedFromWindow(): Unit

onLayout

protected open fun onLayout(changed: Boolean, l: Int, t: Int, r: Int, b: Int): Unit

onMeasure

protected open fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int): Unit

onRestoreInstanceState

protected open fun onRestoreInstanceState(state: Parcelable!): Unit

onSaveInstanceState

protected open fun onSaveInstanceState(): Parcelable!

onSizeChanged

protected open fun onSizeChanged(w: Int, h: Int, oldw: Int, oldh: Int): Unit