抽屉控件 SlidingDrawer相关知识点

【0】先看一段官方描述:

public class

SlidingDrawer

extends  ViewGroup
java.lang.Object
   ↳android.view.View
    ↳android.view.ViewGroup
     ↳android.widget.SlidingDrawer

Class Overview

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:

[html]
  1. <SlidingDrawer  
  2.     android:id="@+id/drawer"  
  3.     android:layout_width="match_parent"  
  4.     android:layout_height="match_parent"  
  5.   
  6.     android:handle="@+id/handle"  
  7.     android:content="@+id/content">  
  8.   
  9.     <ImageView  
  10.         android:id="@id/handle"  
  11.         android:layout_width="88dip"  
  12.         android:layout_height="44dip" />  
  13.   
  14.     <GridView  
  15.         android:id="@id/content"  
  16.         android:layout_width="match_parent"  
  17.         android:layout_height="match_parent" />  
  18.   
  19. </SlidingDrawer>  

【1】简单的说就是:

SlidingDrawer是一个可以实现抽取式显示的控件,可以垂直,水平拉取,每个抽屉都包含两个东西:一个是拉手(handle),一个是抽屉里面的东西(content),SlidingDrawer需要放置在另外的一个layout之上,这意味着SlidingDrawer只能放置在 FrameLayout or a RelativeLayout里面。SlidingDrawer需要设置宽高为match_parent,而且在SlidingDrawer里面必须设置handle与content(显然,不然缺少任何一个都不叫“抽屉”啊)


【2】一些重要的属性与方法:


XML Attributes
Attribute Name Related Method Description
android:allowSingleTap Indicates whether the drawer can be opened/closed by a single tap on the handle.
指示是否可以通过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.指定把手handle
android:orientation Orientation of the SlidingDrawer. 水平还是垂直
android:topOffset Extra offset for the handle at the top of the SlidingDrawer.

Public Methods
void animateClose()
Closes the drawer with an animation. 关闭动画
void animateOpen()
Opens the drawer with an animation. 打开动画
void animateToggle()
Toggles the drawer open and close with an animation.
void close()
Closes the drawer immediately.
View getContent()
Returns the content of the drawer. 获取抽屉的内容
View getHandle()
Returns the handle of the drawer. 获取抽屉的把手
boolean isMoving()
Indicates whether the drawer is scrolling or flinging .判断是否在移动
boolean isOpened()
Indicates whether the drawer is currently fully opened. 是否打开
void lock()
Locks the SlidingDrawer so that touch events are ignores. 锁死抽屉
boolean onInterceptTouchEvent( MotionEvent event)
Implement this method to intercept all touch screen motion events.
boolean onTouchEvent( MotionEvent event)
Implement this method to handle touch screen motion events.
void open()
Opens the drawer immediately. 打开抽屉
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. 设置打开抽屉监听
void setOnDrawerScrollListener( SlidingDrawer.OnDrawerScrollListener onDrawerScrollListener)
Sets the listener that receives a notification when the drawer starts or ends a scroll. 设置拉动抽屉监听
void toggle()
Toggles the drawer open and close. 切换打开和关闭的抽屉。
void unlock()
Unlocks the SlidingDrawer so that touch events are processed. 解锁
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值