Android 控件使用之SlidingDrawer

本文介绍Android中的SlidingDrawer组件使用方法。该组件可在屏幕外隐藏内容,并允许用户通过拖动把手显示内容。适用于垂直或水平方向使用。

   SlidingDrawer 就是Android的抽屉类。它的一个很明显的使用的情况是在Launcher中的效果。可以自己查看Android的源代码来。

这里就简单的说下使用方法:

 

首先在主布局文件里面,写入如下代码:然后再来解释为什么这样写:

 

SlidingDrawer无非就是一个控件,可以在DOC中查看它的属性,说明如下:

 

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 fill_parent for both its dimensions. Inside an XML layout, SlidingDrawer must define the id of the handle and of the content:

 

这个里面我们有两个子控件,一个是handle, 一个是Content,其实也是可以重复叠加的。

 

然后设置handle  图标的样式,在drawable  里添加handle.xml  ,代码如下:

 

Android通过selector改变界面状态 ,它也就是一个资源描述文件。我们在drawable文件夹下面放了三个图片,用来描述按键的状态。

  实际上这样就完成了一个Demo的操作,如果还需要更多的细节,可以参见Launcher的代码。

 

  如果要真正熟悉SlidingDrawer,还得动手写个Demo代码。

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值