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。
猜你喜欢
- 目录1、this代表了()的对象引用,super表示的是当前对象的()对象?2、输出内容是:3、下面程序的输出是:()4、执行下列代码的输出
- 题目要求思路一:暴力模拟由于数据范围不算离谱,所以直接遍历解决可行。Javaclass Solution { pu
- 什么是异步?为什么要用它?异步编程提供了一个非阻塞的,事件驱动的编程模型。 这种编程模型利用系统中多核执行任务来提供并行,因此提供了应用的吞
- 一、maven项目的目录结构pom文件定于了一个maven项目的maven配置,一般pom文件的放在项目或者模块的根目录下。maven的遵循
- No ‘Access-Control-Allow-Origin‘ header is present
- 本文实例为大家分享了Unity实现仿3D轮转图效果的具体代码,供大家参考,具体内容如下一、效果演示二、实现思路—&
- 对单机服务做接口限流的处理方案简单说就是设定某个接口一定时间只接受固定次数的请求,比如/add接口1秒最多接收100次请求,多的直接拒绝,这
- 基于Java的简单的企业员工管理系统,供大家参考,具体内容如下首先创建了一个员工类定义员工应有的属性:工号、姓名、性别、职位、年龄、工资、部
- 如何下载并配置JDK 15进入官网下载JDK 15。官网地址:https://www.oracle.com/index.html脚本之家下载
- 目录结构:Data.xls数据: 后台页面:public void doGet(HttpServletRequest reques
- SimpleDateFormat类:SimpleDateFormat是-一个以与语言环境有关的方式来格式化和解析日期的具体类。进行格式化(日
- 先给大家展示下效果图,大家觉效果满意,请参考实现代码。直接上代码:private void setDialog(){View view =
- Java程序设计 图形用户界面 【十】复选框复选框JCheckBoxJCheckBox类方法作用public JCheckBox(Icon
- 前言MyBatis-Plus 是一个 MyBatis 的增强工具,在 MyBatis 的基础上只做增强不做改变,为简化开发、提高效率而生。那
- 1. @Conditional 注解@Conditional注解是Spring-context模块提供了一个注解,该注解的作用是可以根据一定
- 这里并未涉及到JSR 181 Annotations 的相关应用,具体的三种方式如下① 通过WSDL地址来创建动态客户端 ② 通过服务端提供
- Shiro是什么Shiro是一个Java平台的开源权限框架,用于认证和访问授权。具体来说,满足对如下元素的支持:用户,角色,权限(仅仅是操作
- 自己整理了 spring boot 结合 Redis 的工具类引入依赖<dependency> <groupI
- 由于是多态对象,基类类型的变量可以保存派生类型。 要访问派生类型的实例成员,必须将值强制转换 * 生类型。 但是,强制转换会引发 Invali
- Java实现按行读取大文件String file = "F:" + File.separator + "a.t