belongs to Maven artifact com.android.support:slidingpanelayout:28.0.0-alpha1
SlidingPaneLayout
public
class
SlidingPaneLayout
extends ViewGroup
java.lang.Object | |||
↳ | android.view.View | ||
↳ | android.view.ViewGroup | ||
↳ | android.support.v4.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 | |
---|---|
class |
SlidingPaneLayout.LayoutParams
|
interface |
SlidingPaneLayout.PanelSlideListener
Listener for monitoring events about sliding panes. |
class |
SlidingPaneLayout.SimplePanelSlideListener
No-op stubs for |
Inherited constants |
---|
From
class
android.view.ViewGroup
|
From
class
android.view.View
|
Inherited fields |
---|
From
class
android.view.View
|
Public constructors | |
---|---|
SlidingPaneLayout(Context context)
|
|
SlidingPaneLayout(Context context, AttributeSet attrs)
|
|
SlidingPaneLayout(Context context, AttributeSet attrs, int defStyle)
|
Public methods | |
---|---|
boolean
|
canSlide()
This method was deprecated
in API level 22.1.0.
Renamed to |
boolean
|
closePane()
Close the sliding pane if it is currently slideable. |
void
|
computeScroll()
|
void
|
draw(Canvas c)
|
ViewGroup.LayoutParams
|
generateLayoutParams(AttributeSet attrs)
|
int
|
getCoveredFadeColor()
|
int
|
getParallaxDistance()
|
int
|
getSliderFadeColor()
|
boolean
|
isOpen()
Check if the layout 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)
|
boolean
|
openPane()
Open the sliding pane if it is currently slideable. |
void
|
requestChildFocus(View child, View focused)
|
void
|
setCoveredFadeColor(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. |
void
|
setPanelSlideListener(SlidingPaneLayout.PanelSlideListener listener)
|
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 was deprecated
in API level 22.1.0.
Renamed to |
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 was deprecated
in API level 22.1.0.
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
|
setSliderFadeColor(int color)
Set the color used to fade the sliding pane out when it is slid most of the way offscreen. |
void
|
smoothSlideClosed()
This method was deprecated
in API level 22.1.0.
Renamed to |
void
|
smoothSlideOpen()
This method was deprecated
in API level 22.1.0.
Renamed to |
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 | |
---|---|
From
class
android.view.ViewGroup
| |
From
class
android.view.View
| |
From
class
java.lang.Object
| |
From
interface
android.view.ViewParent
| |
From
interface
android.view.ViewManager
| |
From
interface
android.graphics.drawable.Drawable.Callback
| |
From
interface
android.view.KeyEvent.Callback
| |
From
interface
android.view.accessibility.AccessibilityEventSource
|
Public constructors
SlidingPaneLayout
SlidingPaneLayout (Context context)
Parameters | |
---|---|
context |
Context |
SlidingPaneLayout
SlidingPaneLayout (Context context, AttributeSet attrs)
Parameters | |
---|---|
context |
Context |
attrs |
AttributeSet |
SlidingPaneLayout
SlidingPaneLayout (Context context, AttributeSet attrs, int defStyle)
Parameters | |
---|---|
context |
Context |
attrs |
AttributeSet |
defStyle |
int |
Public methods
canSlide
boolean canSlide ()
This method was deprecated
in API level 22.1.0.
Renamed to isSlideable()
- this method is going away soon!
Returns | |
---|---|
boolean |
true if content in this layout can be slid open and closed |
closePane
boolean closePane ()
Close the sliding pane 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 |
computeScroll
void computeScroll ()
generateLayoutParams
ViewGroup.LayoutParams generateLayoutParams (AttributeSet attrs)
Parameters | |
---|---|
attrs |
AttributeSet |
Returns | |
---|---|
ViewGroup.LayoutParams |
getCoveredFadeColor
int getCoveredFadeColor ()
Returns | |
---|---|
int |
The ARGB-packed color value used to fade the fixed pane |
getParallaxDistance
int getParallaxDistance ()
Returns | |
---|---|
int |
The distance the lower pane will parallax by when the upper pane is fully closed. |
See also:
getSliderFadeColor
int getSliderFadeColor ()
Returns | |
---|---|
int |
The ARGB-packed color value used to fade the sliding pane |
isOpen
boolean isOpen ()
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.
Returns | |
---|---|
boolean |
true if sliding panels are completely open |
isSlideable
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.
Returns | |
---|---|
boolean |
true if content in this layout can be slid open and closed |
onInterceptTouchEvent
boolean onInterceptTouchEvent (MotionEvent ev)
Parameters | |
---|---|
ev |
MotionEvent |
Returns | |
---|---|
boolean |
openPane
boolean openPane ()
Open the sliding pane 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 |
requestChildFocus
void requestChildFocus (View child, View focused)
Parameters | |
---|---|
child |
View |
focused |
View |
setCoveredFadeColor
void setCoveredFadeColor (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 | |
---|---|
color |
int : An ARGB-packed color value
|
setPanelSlideListener
void setPanelSlideListener (SlidingPaneLayout.PanelSlideListener listener)
Parameters | |
---|---|
listener |
SlidingPaneLayout.PanelSlideListener |
setParallaxDistance
void setParallaxDistance (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 | |
---|---|
parallaxBy |
int : Distance to parallax by in pixels
|
setShadowDrawable
void setShadowDrawable (Drawable d)
This method was deprecated
in API level 22.1.0.
Renamed to setShadowDrawableLeft(Drawable)
to support LTR (left to
right language) and setShadowDrawableRight(Drawable)
to support RTL (right to left
language) during opening/closing.
Parameters | |
---|---|
d |
Drawable : drawable to use as a shadow
|
setShadowDrawableLeft
void setShadowDrawableLeft (Drawable d)
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
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.
Parameters | |
---|---|
d |
Drawable : drawable to use as a shadow
|
setShadowResource
void setShadowResource (int resId)
This method was deprecated
in API level 22.1.0.
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
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 | |
---|---|
resId |
int : Resource ID of a drawable to use
|
setShadowResourceRight
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 | |
---|---|
resId |
int : Resource ID of a drawable to use
|
setSliderFadeColor
void setSliderFadeColor (int color)
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
void smoothSlideClosed ()
This method was deprecated
in API level 22.1.0.
Renamed to closePane()
- this method is going away soon!
smoothSlideOpen
void smoothSlideOpen ()
This method was deprecated
in API level 22.1.0.
Renamed to openPane()
- this method is going away soon!
Protected methods
canScroll
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 | |
---|---|
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. |
checkLayoutParams
boolean checkLayoutParams (ViewGroup.LayoutParams p)
Parameters | |
---|---|
p |
ViewGroup.LayoutParams |
Returns | |
---|---|
boolean |
drawChild
boolean drawChild (Canvas canvas, View child, long drawingTime)
Parameters | |
---|---|
canvas |
Canvas |
child |
View |
drawingTime |
long |
Returns | |
---|---|
boolean |
generateDefaultLayoutParams
ViewGroup.LayoutParams generateDefaultLayoutParams ()
Returns | |
---|---|
ViewGroup.LayoutParams |
generateLayoutParams
ViewGroup.LayoutParams generateLayoutParams (ViewGroup.LayoutParams p)
Parameters | |
---|---|
p |
ViewGroup.LayoutParams |
Returns | |
---|---|
ViewGroup.LayoutParams |
onAttachedToWindow
void onAttachedToWindow ()
onDetachedFromWindow
void onDetachedFromWindow ()
onLayout
void onLayout (boolean changed, int l, int t, int r, int b)
Parameters | |
---|---|
changed |
boolean |
l |
int |
t |
int |
r |
int |
b |
int |
onMeasure
void onMeasure (int widthMeasureSpec, int heightMeasureSpec)
Parameters | |
---|---|
widthMeasureSpec |
int |
heightMeasureSpec |
int |
onSizeChanged
void onSizeChanged (int w, int h, int oldw, int oldh)
Parameters | |
---|---|
w |
int |
h |
int |
oldw |
int |
oldh |
int |
Interfaces
Classes
- AutoScrollHelper
- CircularProgressDrawable
- CompoundButtonCompat
- ContentLoadingProgressBar
- CursorAdapter
- DrawerLayout
- DrawerLayout.LayoutParams
- DrawerLayout.SavedState
- DrawerLayout.SimpleDrawerListener
- EdgeEffectCompat
- ExploreByTouchHelper
- ImageViewCompat
- ListPopupWindowCompat
- ListViewAutoScrollHelper
- ListViewCompat
- NestedScrollView
- PopupMenuCompat
- PopupWindowCompat
- ResourceCursorAdapter
- ScrollerCompat
- SimpleCursorAdapter
- SlidingPaneLayout
- SlidingPaneLayout.LayoutParams
- SlidingPaneLayout.SimplePanelSlideListener
- Space
- SwipeRefreshLayout
- TextViewCompat
- ViewDragHelper
- ViewDragHelper.Callback
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 2024-04-11 UTC.