Widget Catalog: SlidingDrawer

Having some form of means of allowing the user to swipe to
show more things is an important visual pattern. We saw
this earlier in the book with the ViewPager container.
And there are other modern techniques for doing this that you will
see in apps like Google+.

SlidingDrawer, while implementing a variation on this pattern, is a
bit out of date at present. Mostly, that’s a question of its UI: tapping
a drawer “handle” to open it is not what you tend to see nowadays.
That being said, it works perfectly well, wrapping around a container
to make it appear or disappear based on user input, complete with a sliding
animation effect.

Note that SlidingDrawer was deprecated in API Level 17 (a.k.a., Android 4.2).
This means that Google is steering you in other directions, including forking
the AOSP code for SlidingDrawer
and maintaining it yourself. The
animator framework offers other ways of implementing
sliding widgets that may be better suited for your UI, anyway.

Also note that SlidingDrawer is broken on Android 5.0, and so you
definitely should be considering alternative widgets at this time.

Key Usage Tips

The SlidingDrawer itself is transparent, except for the button to
trigger the slide and its accompanying horizontal bar. Hence, if you want
the drawer contents to completely obscure what is outside of the drawer,
you will need to use an appropriate background. Otherwise, the drawer
contents and what lies outside the drawer will be alpha-blended based
on their own translucency, as is seen in
the screenshots later in this chapter.

The SlidingDrawer can be horizontal or vertical; it is vertical by
default. However, it only slides one way (bottom-to-top for vertical,
right-to-left for horizontal). There is no way to reverse the direction
of the sliding effect.

You must supply android:content and android:handle attributes
in SlidingDrawer, containing references to the widget that forms
the content of the drawer and the drawer’s handle, respectively.
Typically, the drawer’s handle is an ImageView. Note that you must
supply a handle — you cannot skip either of these attributes.

packagecom.commonsware.android.drawer;importandroid.app.Activity;importandroid.os.Bundle;publicclassDrawerDemoextendsActivity{/** Called when the activity is first created. */@OverridepublicvoidonCreate(BundlesavedInstanceState){super.onCreate(savedInstanceState);setContentView(R.layout.main);}}