android的抽屉效果,Android SlidingDrawer 抽屉效果的实现

本文介绍了如何在Android应用中使用SlidingDrawer组件,包括其基本结构、关键属性如`android:allowSingleTap`和`android:animateOnClick`,以及重要方法如`animateClose()`和`toggle()`. 学习如何设置handle和content视图,以及如何通过编程控制滑动行为和动画效果。
摘要由CSDN通过智能技术生成

SlidingDrawer隐藏屏外的内容,并允许用户通过handle以显示隐藏内容。它可以垂直或水平滑动,它有俩个View组成,其一是可以拖动的handle,其二是隐藏内容的View.它里面的控件必须设置布局,在布局文件中必须指定handle和content。

1、布局layou文件

复制代码 代码如下:

android:layout_width="match_parent"

android:layout_height="match_parent"

android:orientation="vertical" >

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="@string/hello_world" />

android:id="@+id/slidingdrawer"

android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:content="@+id/content"

android:handle="@+id/handle"

android:orientation="vertical" >

android:id="@+id/handle"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="SlidingDraser" />

android:id="@+id/content"

android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:background="#00ffaa" >

android:id="@+id/button"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Button" />

android:id="@+id/editText"

android:layout_width="fill_parent"

android:layout_height="wrap_content" />

2、下面是运行程序之后的界面

1-21011014140S43.jpg

1-21011014135BA.jpg

另:可在drawable中添加文件

复制代码 代码如下:

总结:

1、重要属性

android:allowSingleTap:指示是否可以通过handle打开或关闭

android:animateOnClick:指示是否当使用者按下手柄打开/关闭时是否该有一个动画。

android:content:隐藏的内容

android:handle:handle(手柄)

2、重要方法

animateClose():关闭时实现动画。

close():即时关闭

getContent():获取内容

isMoving():指示SlidingDrawer是否在移动。

isOpened():指示SlidingDrawer是否已全部打开

lock():屏蔽触摸事件。

setOnDrawerCloseListener(SlidingDrawer.OnDrawerCloseListener onDrawerCloseListener):SlidingDrawer关闭时调用

setOnDrawerOpenListener

setOnDrawerScrollListener

unlock():解除屏蔽触摸事件。

toggle():切换打开和关闭的抽屉SlidingDrawer。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值