Android SlidingDrawer 抽屉效果的实现
发布时间:2023-08-02 07:58:30
SlidingDrawer隐藏屏外的内容,并允许用户通过handle以显示隐藏内容。它可以垂直或水平滑动,它有俩个View组成,其一是可以拖动的handle,其二是隐藏内容的View.它里面的控件必须设置布局,在布局文件中必须指定handle和content。
1、布局layou文件
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" />
<SlidingDrawer
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" >
<Button
android:id="@+id/handle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="SlidingDraser" />
<LinearLayout <!--隐藏的内容-->
android:id="@+id/content"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#00ffaa" >
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
<EditText
android:id="@+id/editText"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</SlidingDrawer>
</LinearLayout>
2、下面是运行程序之后的界面
另:可在drawable中添加文件
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_window_focused="false" android:state_enabled="true" android:drawable="@drawable/handle_normal" />
<item android:state_pressed="true" android:drawable="@drawable/handle_pressed" />
<item android:state_focused="true" android:state_enabled="true" android:drawable="@drawable/handle_focused" />
<item android:state_enabled="true" android:drawable="@drawable/handle_normal" />
<item android:state_focused="true" android:drawable="@drawable/handle_focused" />
</selector>
总结:
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。


猜你喜欢
- *注:可以用 adb logcat > 路径/文件名 来保存,此命令执行之时起的全部日志信息到一个文件里,ctrl + C 结束日志输
- springcloud eureka切换nacos配置中心地址: http://10.166.9.7:8848/nacos/bootstra
- 以上是集成测试后的Jprofiler演示效果图今晚想在IDEA中集成一下JProfiler11(现在有12版本了)工具,去网上看了下都是老版
- Random类 (java.util) Ran
- 目录前言代码一:代码二:方式一:方式二:方式三:总结前言之前写过多线程累加计数,原理跟本篇类似,传送门累加计数比计算数组之和逻辑稍微简单一点
- 我就废话不多说了,大家还是直接看代码吧~ public static void main(String[] args) { &n
- 简述Preference是Android的控件之一,相对来说我们用的比较少,但在系统应用的Settings设置应用模块中大部分由Prefer
- instanceof关键字的使用1. 语法格式x instanceof A:检验x是否为类A的对象,返回值为boolean类型,如果是,返回
- Collections是一个工具类,sort是其中的静态方法,是用来对List类型进行排序的,它有两种参数形式: public static
- 本文实例为大家分享了Unity使用鼠标旋转物体效果的具体代码,供大家参考,具体内容如下了解完基础知识后,然我们来做个小程序练习一下1.在Ma
- 前言在实现红黑树之前,我们先来了解一下符号表。符号表的描述借鉴了Algorithms第四版,详情在:https://algs4.cs.pri
- WPF实现 Gitee泡泡菜单框架使用大于等于.NET40;Visual Studio 2022;项目使用 MIT 开源
- 本文实例讲述了JDBC基础知识与技巧。分享给大家供大家参考。具体分析如下:1.什么是JDBC?通俗来讲JDBC技术就是通过java程序来发送
- 先执行以一个简单的示例:static void Main(string[] args) { &nb
- C# 中可以将类、结构或接口的定义拆分到两个或多个源文件中,在类声明前添加partial关键字即可。1. 什么是局部类型?C# 2.0 引入
- 本文实例讲述了C#实现基于XML配置MenuStrip菜单的方法。分享给大家供大家参考。具体如下:1.关于本程序的说明用XML配置MenuS
- 网络应用分为客户端和服务端两部分,而Socket类是负责处理客户端通信的Java类。通过这个类可以连接到指定IP或域名的服务器上,并且可以和
- 本文实例为大家分享了struts2实现文件上传下载的具体实现代码,供大家参考,具体内容如下一、文件上传 struts提交的文件组件上传, 前
- 引言最近的项目需求中有使用到后端发送http请求,在网上寻找资料后发现可以使用spring自带的RestTemplate类实现,故作此记录项
- 本文实例讲述了Android编程开发之TextView单击链接弹出Activity的方法。分享给大家供大家参考,具体如下:话不多说直接上码: