滑动式抽屉_SlidingDrawer

来源:互联网 发布:自学美工要下什么软件 编辑:程序博客网 时间:2024/04/29 13:09

http://developer.android.com/reference/android/widget/SlidingDrawer.html

应用场景:从下边或者右边拖出或弹出一个控件,提供操作快捷方式;

问题:滑动抽屉由什么组成?把手和隐藏控件;handle and content

思考:1.抽屉的把手用什么做?drag a handle to bring the content on screen

            2.隐藏控件用什么做?SlidingDrawer hides content out of the screen

            3.滑动抽屉有什么监听器?

      总之都是view对象,handle可以用ImageView来做,也可用TextView来做,毕竟它们都是view的子类;

       content也一样,可以装一个GridView 也可以是一个ListView,也可以是一个LinearLayout,其中有多个View对象;

       监听器:滑动时 OnDrawerScrollListener

                       打开时 OnDrawerOpenListener

                       关闭时 OnDrawerCloseListener


接口简介:

interfaceSlidingDrawer.OnDrawerCloseListenerCallback invoked when the drawer is closed. interfaceSlidingDrawer.OnDrawerOpenListenerCallback invoked when the drawer is opened. interfaceSlidingDrawer.OnDrawerScrollListenerCallback invoked when the drawer is scrolled. 


类的简介:

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:


操作步骤:

     1.在布局文件中,配置对象,该对象应该放在FrameLayout或RelativeLayout中;

 <SlidingDrawer     android:id="@+id/drawer"     android:layout_width="match_parent"     android:layout_height="match_parent"     android:handle="@+id/handle"     android:content="@+id/content">     <ImageView         android:id="@id/handle"         android:layout_width="88dip"         android:layout_height="44dip" />     <GridView         android:id="@id/content"         android:layout_width="match_parent"         android:layout_height="match_parent" /> </SlidingDrawer>
       2.在程序代码中,设置监听,获取控件,设置监听;