added in version 1.0.0
belongs to Maven artifact androidx.wear:wear:1.0.0-beta01

WearableDrawerLayout

public class WearableDrawerLayout
extends FrameLayout implements View.OnLayoutChangeListener, NestedScrollingParent

java.lang.Object
   ↳ android.view.View
     ↳ android.view.ViewGroup
       ↳ android.widget.FrameLayout
         ↳ androidx.wear.widget.drawer.WearableDrawerLayout


Top-level container that allows interactive drawers to be pulled from the top and bottom edge of the window. For WearableDrawerLayout to work properly, scrolling children must send nested scrolling events. Views that implement NestedScrollingChild do this by default. To enable nested scrolling on frameworks views like ListView, set android:nestedScrollingEnabled="true" on the view in the layout file, or call View.setNestedScrollingEnabled(boolean) in code. This includes the main content in a WearableDrawerLayout, as well as the content inside of the drawers.

To use WearableDrawerLayout with WearableActionDrawerView or WearableNavigationDrawerView, place either drawer in a WearableDrawerLayout.

 <androidx.wear.widget.drawer.WearableDrawerLayout [...]>
     <FrameLayout android:id=”@+id/content” />

     <androidx.wear.widget.drawer.WearableNavigationDrawerView
         android:layout_width=”match_parent”
         android:layout_height=”match_parent” />

     <androidx.wear.widget.drawer.WearableActionDrawerView
         android:layout_width=”match_parent”
         android:layout_height=”match_parent” />

 </androidx.wear.widget.drawer.WearableDrawerLayout>

To use custom content in a drawer, place WearableDrawerView in a WearableDrawerLayout and specify the layout_gravity to pick the drawer location (the following example is for a top drawer). Note: You must either call WearableDrawerView.setDrawerContent(View) and pass in your drawer content view, or specify it in the app:drawerContent XML attribute.

 <androidx.wear.widget.drawer.WearableDrawerLayout [...]>
     <FrameLayout
         android:id=”@+id/content”
         android:layout_width=”match_parent”
         android:layout_height=”match_parent” />

     <androidx.wear.widget.drawer.WearableDrawerView
         android:layout_width=”match_parent”
         android:layout_height=”match_parent”
         android:layout_gravity=”top”
         app:drawerContent="@+id/top_drawer_content" >

         <FrameLayout
             android:id=”@id/top_drawer_content”
             android:layout_width=”match_parent”
             android:layout_height=”match_parent” />

     </androidx.wear.widget.drawer.WearableDrawerView>
 </androidx.wear.widget.drawer.WearableDrawerLayout>

Summary

Nested classes

class WearableDrawerLayout.DrawerStateCallback

Listener for monitoring events about drawers. 

Inherited constants

Inherited fields

Public constructors

WearableDrawerLayout(Context context)
WearableDrawerLayout(Context context, AttributeSet attrs)
WearableDrawerLayout(Context context, AttributeSet attrs, int defStyleAttr)
WearableDrawerLayout(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes)

Public methods

void addView(View child, int index, ViewGroup.LayoutParams params)
void computeScroll()
int getNestedScrollAxes()
WindowInsets onApplyWindowInsets(WindowInsets insets)
void onFlingComplete(View view)
boolean onInterceptTouchEvent(MotionEvent ev)
void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom)
boolean onNestedFling(View target, float velocityX, float velocityY, boolean consumed)
boolean onNestedPreFling(View target, float velocityX, float velocityY)
void onNestedPreScroll(View target, int dx, int dy, int[] consumed)
void onNestedScroll(View target, int dxConsumed, int dyConsumed, int dxUnconsumed, int dyUnconsumed)
void onNestedScrollAccepted(View child, View target, int nestedScrollAxes)
boolean onStartNestedScroll(View child, View target, int nestedScrollAxes)
void onStopNestedScroll(View target)
boolean onTouchEvent(MotionEvent ev)
void setDrawerStateCallback(WearableDrawerLayout.DrawerStateCallback callback)

Sets a listener to be notified of drawer events.

Protected methods

void onLayout(boolean changed, int left, int top, int right, int bottom)

Inherited methods

Public constructors

WearableDrawerLayout

added in version 1.0.0
public WearableDrawerLayout (Context context)

Parameters
context Context

WearableDrawerLayout

added in version 1.0.0
public WearableDrawerLayout (Context context, 
                AttributeSet attrs)

Parameters
context Context

attrs AttributeSet

WearableDrawerLayout

added in version 1.0.0
public WearableDrawerLayout (Context context, 
                AttributeSet attrs, 
                int defStyleAttr)

Parameters
context Context

attrs AttributeSet

defStyleAttr int

WearableDrawerLayout

added in version 1.0.0
public WearableDrawerLayout (Context context, 
                AttributeSet attrs, 
                int defStyleAttr, 
                int defStyleRes)

Parameters
context Context

attrs AttributeSet

defStyleAttr int

defStyleRes int

Public methods

addView

public void addView (View child, 
                int index, 
                ViewGroup.LayoutParams params)

Parameters
child View

index int

params ViewGroup.LayoutParams

computeScroll

public void computeScroll ()

getNestedScrollAxes

public int getNestedScrollAxes ()

Returns
int

onApplyWindowInsets

public WindowInsets onApplyWindowInsets (WindowInsets insets)

Parameters
insets WindowInsets

Returns
WindowInsets

onFlingComplete

added in version 1.0.0
public void onFlingComplete (View view)

Parameters
view View

onInterceptTouchEvent

public boolean onInterceptTouchEvent (MotionEvent ev)

Parameters
ev MotionEvent

Returns
boolean

onLayoutChange

added in version 1.0.0
public void onLayoutChange (View v, 
                int left, 
                int top, 
                int right, 
                int bottom, 
                int oldLeft, 
                int oldTop, 
                int oldRight, 
                int oldBottom)

Parameters
v View

left int

top int

right int

bottom int

oldLeft int

oldTop int

oldRight int

oldBottom int

onNestedFling

public boolean onNestedFling (View target, 
                float velocityX, 
                float velocityY, 
                boolean consumed)

Parameters
target View

velocityX float

velocityY float

consumed boolean

Returns
boolean

onNestedPreFling

public boolean onNestedPreFling (View target, 
                float velocityX, 
                float velocityY)

Parameters
target View

velocityX float

velocityY float

Returns
boolean

onNestedPreScroll

public void onNestedPreScroll (View target, 
                int dx, 
                int dy, 
                int[] consumed)

Parameters
target View

dx int

dy int

consumed int

onNestedScroll

public void onNestedScroll (View target, 
                int dxConsumed, 
                int dyConsumed, 
                int dxUnconsumed, 
                int dyUnconsumed)

Parameters
target View

dxConsumed int

dyConsumed int

dxUnconsumed int

dyUnconsumed int

onNestedScrollAccepted

public void onNestedScrollAccepted (View child, 
                View target, 
                int nestedScrollAxes)

Parameters
child View

target View

nestedScrollAxes int

onStartNestedScroll

public boolean onStartNestedScroll (View child, 
                View target, 
                int nestedScrollAxes)

Parameters
child View

target View

nestedScrollAxes int

Returns
boolean

onStopNestedScroll

public void onStopNestedScroll (View target)

Parameters
target View

onTouchEvent

public boolean onTouchEvent (MotionEvent ev)

Parameters
ev MotionEvent

Returns
boolean

setDrawerStateCallback

added in version 1.0.0
public void setDrawerStateCallback (WearableDrawerLayout.DrawerStateCallback callback)

Sets a listener to be notified of drawer events.

Parameters
callback WearableDrawerLayout.DrawerStateCallback

Protected methods

onLayout

protected void onLayout (boolean changed, 
                int left, 
                int top, 
                int right, 
                int bottom)

Parameters
changed boolean

left int

top int

right int

bottom int