原地址:http://blog.csdn.net/moreevan/article/details/6741083
我们来看一下官方文档中对这个控件 的定义:
SlidingDrawer hides content out of the screen and allows the user to drag a handle to bring the content on screen. SlidingDrawer can be used vertically or horizontally. A special widget composed of two children views: the handle, that the users drags, and the content, attached to the handle and dragged with it. SlidingDrawer should be used as an overlay inside layouts. This means SlidingDrawer should only be used inside of a FrameLayout or a RelativeLayout for instance. The size of the SlidingDrawer defines how much space the content will occupy once slid out so SlidingDrawer should usually use match_parent for both its dimensions. Inside an XML layout, SlidingDrawer must define the id of the handle and of the content:
其实android1.5的应用程序列表就应用了这个控件。
我们来看一下它特有的xml属性
XML Attributes | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Attribute Name | Related Method | Description | |||||||||
android:allowSingleTap | Indicates whether the drawer can be opened/closed by a single tap on the handle. | ||||||||||
android:animateOnClick | Indicates whether the drawer should be opened/closed with an animation when the user clicks the handle. | ||||||||||
android:bottomOffset | Extra offset for the handle at the bottom of the SlidingDrawer. | ||||||||||
android:content | Identifier for the child that represents the drawer's content. | ||||||||||
android:handle | Identifier for the child that represents the drawer's handle. | ||||||||||
android:orientation | Orientation of the SlidingDrawer. | ||||||||||
android:topOffset | Extra offset for the handle at the top of the SlidingDrawer. |
先来看一下最终的效果截个图:
两张图分别对应SlidingDrawer关闭时和打开时的视图
看一下layout的定义
这里在SlidingDrawer元素里必须指定它的handle和content属性
再看一下Activity的实现:
它最重要的两个方法就是在代码中提到的
void |
setOnDrawerCloseListener(
SlidingDrawer.OnDrawerCloseListener onDrawerCloseListener)
Sets the listener that receives a notification when the drawer becomes close.
|
void |
setOnDrawerOpenListener(
SlidingDrawer.OnDrawerOpenListener onDrawerOpenListener)
Sets the listener that receives a notification when the drawer becomes open.
|