简介
DrawerLayout中包含主视图和子视图
主视图为为match_parent的宽度和高度
子视图高度为match_parent,宽度可自由设置,需要设置layout_gravity表示弹出方向
内部内
- interface DrawerListener
onDrawerClosed(View drawerView) 当抽屉处于完全关闭状态时调用。
onDrawerOpened(View drawerView) 当抽屉完全处于打开状态时调用。
onDrawerSlide(View drawerView, float slideOffset) 当抽屉的位置改变时调用。
drawerView 抽屉视图
slideOffset 抽屉视图移动距离,范围0-1
onDrawerStateChanged(int newState) 当抽屉运动状态改变时调用。
newState 运动状态
DrawerLayout.STATE_IDLE 抽屉处于空闲、稳定状态。没有动画正在进行中。
DrawerLayout.STATE_DRAGGING 用户当前正在拖动抽屉。
DrawerLayout.STATE_SETTLING 执行打开或关闭的动画过程中
。
- LayoutParams
- SavedState 通过实例保存状态
- SimpleDrawerListener 是DrawerListener的实现类,与DrawerListener不同的是,DrawerListener必须实现所有方法,SimpleDrawerListener可以只实现需要的方法
常量
LOCK_MODE_LOCKED_CLOSED 锁定并关闭菜单,用户无法侧滑,但是程序调用可以实现侧滑
LOCK_MODE_LOCKED_OPEN 锁定并打开菜单,用户无法侧滑,但是程序调用可以实现侧滑
LOCK_MODE_UNDEFINED 空白状态,初始状态
LOCK_MODE_UNLOCKED 未锁定,用户可以活动侧滑
STATE_DRAGGING 用户当前正在拖动抽屉
STATE_IDLE 抽屉处于空闲、稳定状态。没有动画正在进行中
STATE_SETTLING 执行打开或关闭的动画过程中
public method
addDrawerListener(DrawerLayout.DrawerListener listener)
addFocusables(ArrayList<View> views, int direction, int focusableMode)
addView(View child, int index, ViewGroup.LayoutParams params)
closeDrawer(View drawerView)
closeDrawer(int gravity)
closeDrawer(View drawerView, boolean animate)
closeDrawer(int gravity, boolean animate)
closeDrawers()
computeScroll()
dispatchGenericMotionEvent(MotionEvent event)
generateLayoutParams(AttributeSet attrs)
getDrawerElevation()
getDrawerLockMode(int edgeGravity)
getDrawerLockMode(View drawerView)
getDrawerTitle(int edgeGravity)
getStatusBarBackgroundDrawable()
isDrawerOpen(View drawer)
isDrawerOpen(int drawerGravity)
isDrawerVisible(View drawer)
isDrawerVisible(int drawerGravity)
onDraw(Canvas c)
onInterceptTouchEvent(MotionEvent ev)
onKeyDown(int keyCode, KeyEvent event)
onKeyUp(int keyCode, KeyEvent event)
onRtlPropertiesChanged(int layoutDirection)
onTouchEvent(MotionEvent ev)
openDrawer(View drawerView, boolean animate)
openDrawer(View drawerView)
openDrawer(int gravity)
openDrawer(int gravity, boolean animate)
removeDrawerListener(DrawerLayout.DrawerListener listener)
requestDisallowInterceptTouchEvent(boolean disallowIntercept)
requestLayout()
setDrawerElevation(float elevation)
setDrawerListener(DrawerLayout.DrawerListener listener)
setDrawerLockMode(int lockMode, View drawerView)
setDrawerLockMode(int lockMode)
setDrawerLockMode(int lockMode, int edgeGravity)
setDrawerShadow(int resId, int gravity)
setDrawerShadow(Drawable shadowDrawable, int gravity)
setDrawerTitle(int edgeGravity, CharSequence title)
setScrimColor(int color)
setStatusBarBackground(Drawable bg)
setStatusBarBackground(int resId)
setStatusBarBackgroundColor(int color)
protected methed
checkLayoutParams(ViewGroup.LayoutParams p)
drawChild(Canvas canvas, View child, long drawingTime)
generateDefaultLayoutParams()
generateLayoutParams(ViewGroup.LayoutParams p)
onAttachedToWindow()
onDetachedFromWindow()
onLayout(boolean changed, int l, int t, int r, int b)
onMeasure(int widthMeasureSpec, int heightMeasureSpec)
onRestoreInstanceState(Parcelable state)
onSaveInstanceState()