belongs to Maven artifact com.android.support:drawerlayout:28.0.0-alpha1
DrawerLayout
public
class
DrawerLayout
extends ViewGroup
java.lang.Object | |||
↳ | android.view.View | ||
↳ | android.view.ViewGroup | ||
↳ | android.support.v4.widget.DrawerLayout |
DrawerLayout acts as a top-level container for window content that allows for interactive "drawer" views to be pulled out from one or both vertical edges of the window.
Drawer positioning and layout is controlled using the android:layout_gravity
attribute on child views corresponding to which side of the view you want the drawer
to emerge from: left or right (or start/end on platform versions that support layout direction.)
Note that you can only have one drawer view for each vertical edge of the window. If your
layout configures more than one drawer view per vertical edge of the window, an exception will
be thrown at runtime.
To use a DrawerLayout, position your primary content view as the first child with
width and height of match_parent
and no layout_gravity>
.
Add drawers as child views after the main content view and set the layout_gravity
appropriately. Drawers commonly use match_parent
for height with a fixed width.
DrawerLayout.DrawerListener
can be used to monitor the state and motion of drawer views.
Avoid performing expensive operations such as layout during animation as it can cause
stuttering; try to perform expensive operations during the STATE_IDLE
state.
DrawerLayout.SimpleDrawerListener
offers default/no-op implementations of each callback method.
As per the Android Design guide, any drawers positioned to the left/start should always contain content for navigating around the application, whereas any drawers positioned to the right/end should always contain actions to take on the current content. This preserves the same navigation left, actions right structure present in the Action Bar and elsewhere.
For more information about how to use DrawerLayout, read Creating a Navigation Drawer.
Summary
Nested classes | |
---|---|
interface |
DrawerLayout.DrawerListener
Listener for monitoring events about drawers. |
class |
DrawerLayout.LayoutParams
|
class |
DrawerLayout.SavedState
State persisted across instances |
class |
DrawerLayout.SimpleDrawerListener
Stub/no-op implementations of all methods of |
Constants | |
---|---|
int |
LOCK_MODE_LOCKED_CLOSED
The drawer is locked closed. |
int |
LOCK_MODE_LOCKED_OPEN
The drawer is locked open. |
int |
LOCK_MODE_UNDEFINED
The drawer's lock state is reset to default. |
int |
LOCK_MODE_UNLOCKED
The drawer is unlocked. |
int |
STATE_DRAGGING
Indicates that a drawer is currently being dragged by the user. |
int |
STATE_IDLE
Indicates that any drawers are in an idle, settled state. |
int |
STATE_SETTLING
Indicates that a drawer is in the process of settling to a final position. |
Inherited constants |
---|
![]()
android.view.ViewGroup
|
![]()
android.view.View
|
Inherited fields |
---|
![]()
android.view.View
|
Public constructors | |
---|---|
DrawerLayout(Context context)
|
|
DrawerLayout(Context context, AttributeSet attrs)
|
|
DrawerLayout(Context context, AttributeSet attrs, int defStyle)
|
Public methods | |
---|---|
void
|
addDrawerListener(DrawerLayout.DrawerListener listener)
Adds the specified listener to the list of listeners that will be notified of drawer events. |
void
|
addFocusables(ArrayList<View> views, int direction, int focusableMode)
|
void
|
addView(View child, int index, ViewGroup.LayoutParams params)
|
void
|
closeDrawer(View drawerView)
Close the specified drawer view by animating it into view. |
void
|
closeDrawer(int gravity)
Close the specified drawer by animating it out of view. |
void
|
closeDrawer(View drawerView, boolean animate)
Close the specified drawer view. |
void
|
closeDrawer(int gravity, boolean animate)
Close the specified drawer. |
void
|
closeDrawers()
Close all currently open drawer views by animating them out of view. |
void
|
computeScroll()
|
ViewGroup.LayoutParams
|
generateLayoutParams(AttributeSet attrs)
|
float
|
getDrawerElevation()
The base elevation of the drawer(s) relative to the parent, in pixels. |
int
|
getDrawerLockMode(int edgeGravity)
Check the lock mode of the drawer with the given gravity. |
int
|
getDrawerLockMode(View drawerView)
Check the lock mode of the given drawer view. |
CharSequence
|
getDrawerTitle(int edgeGravity)
Returns the title of the drawer with the given gravity. |
Drawable
|
getStatusBarBackgroundDrawable()
Gets the drawable used to draw in the insets area for the status bar. |
boolean
|
isDrawerOpen(View drawer)
Check if the given drawer view is currently in an open state. |
boolean
|
isDrawerOpen(int drawerGravity)
Check if the given drawer view is currently in an open state. |
boolean
|
isDrawerVisible(View drawer)
Check if a given drawer view is currently visible on-screen. |
boolean
|
isDrawerVisible(int drawerGravity)
Check if a given drawer view is currently visible on-screen. |
void
|
onDraw(Canvas c)
|
boolean
|
onInterceptTouchEvent(MotionEvent ev)
|
boolean
|
onKeyDown(int keyCode, KeyEvent event)
|
boolean
|
onKeyUp(int keyCode, KeyEvent event)
|
void
|
onRtlPropertiesChanged(int layoutDirection)
|
boolean
|
onTouchEvent(MotionEvent ev)
|
void
|
openDrawer(View drawerView, boolean animate)
Open the specified drawer view. |
void
|
openDrawer(View drawerView)
Open the specified drawer view by animating it into view. |
void
|
openDrawer(int gravity)
Open the specified drawer by animating it out of view. |
void
|
openDrawer(int gravity, boolean animate)
Open the specified drawer. |
void
|
|