Android学习之nbsp;Launcher抽屉类Slid…
Android Launcher抽屉类SlidingDrawer的使用
最近在研究Lanucher ,看了源码,发现了SlidingDrawer 这个类,也就是所谓的"抽屉"类。它的用法很简单,要包括handle ,和content .
handle 就是当你点击它的时候,content 要么抽抽屉要么关抽屉。别的不多说了,具体步骤如下.
1.新建Android 工程,命名为SlidingDrawer .
2.准备素材,在这里我的图标是用Launcher2 里面的图标,放在drawable-hdpi 文件夹目录结构如下:
3.设置main.xml 布局:代码如下:
view plaincopy to clipboardprint?
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#808080"
>
<SlidingDrawer
android:id="@+id/slidingdrawer"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:handle="@+id/handle"
android:content="@+id/content">
<Button
android:id="@+id/handle"
android:layout_width="88dip"
android:layout_height="44dip"
android:background="@drawable/handle"
/>
<LinearLayout
android:id="@+id/content"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#00ff00">
<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>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#808080"
>
<SlidingDrawer
android:id="@+id/slidingdrawer"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:handle="@+id/handle"
android:content="@+id/content">
<Button
android:id="@+id/handle"
android:layout_width="88dip"
android:layout_height="44dip"
android:background="@drawable/handle"
/>
<LinearLayout
android:id="@+id/content"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#00ff00">
<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>
4.设置handle 图标的样式,在drawable 里添加handle.xml ,代码如下:
view plaincopy to clipboardprint?
<?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>
<?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>
5.运行之。将会得到如下效果:
的比较简单呵呵,如果想深入了解,大家看Launcher 源码吧!
转载http://blog.csdn.net/Android_Tutor/archive/2010/04/14/5486804.aspx
Android学习之nbsp;Launcher抽屉类Slid…相关推荐
- 列表怎么有限的初始化为零_《零基础学习Android开发》第五课 类与面向对象编程1-1...
视频:<零基础学习Android开发>第五课 类与面向对象编程1-1 类的定义.成员变量.构造方法.成员方法 一.从数据与逻辑相互关系审视代码 通过前面的课程,我们不断接触Java语言的知 ...
- Android学习之Pair类 (android.util.Pair )
官方文档:https://developer.android.com/reference/android/util/Pair.html 原文地址: http://blog.csdn.net/qq_24 ...
- 的Android组件、工具、框架大全(转) android 学习 android 例子 android 开源项目
2015最流行的Android组件.工具.框架大全(转) 转自:2015最流行的Android组件.工具.框架大全 Android 是目前最流行的移动操作系统之一. 随着新版本的不断发布, Andro ...
- Android学习笔记之AndroidManifest.xml文件解析(摘自皮狼的博客)
Android学习笔记之AndroidManifest.xml文件解析 一.关于AndroidManifest.xml AndroidManifest.xml 是每个android程序中必须的文件.它 ...
- android自定义桌面(launcher)
有时候需要开发一个自己的桌面程序,特别是做产品开发的开发人员,android自定义桌面其实就是一个launcher,然后在相应的activity中把系统中的所有APK加载进来,显示相应的icon图标. ...
- android学习十八(Service服务的基本用法)
定义一个服务 在项目中定义一个服务,新建一个ServiceTest项目,然后在这个项目中新增一个名为MyService的类,并让它继承自Service,完成后的代码如下所示: package com. ...
- Android学习博客和文章存档
[Android基础]Android总结篇 http://blog.csdn.net/codeemperor/article/details/51004189 Android最佳性能实践(一)--合理 ...
- Android学习——UI高级组件三
Android学习--UI高级组件三 PopupWindow(弹出式窗口) Android的对话框有两种:PopupWindow和AlertDialog.它们的不同点在于:AlertDialog位置固 ...
- Android学习笔记:Android基础知识点(不断更新中)
1.Android学习笔记:OkHttp 2.Android学习笔记:更新UI的方法(UI线程和非UI线程) 3.Android学习笔记:Volley 4.Android学习笔记:Handler 5. ...
最新文章
- 宜春学院计算机专业好就业吗,宜春学院毕业生良好就业前景的背后
- [IE技巧] 如何禁止用户关闭IE浏览器
- Python自动化运维——系统性能信息模块
- c++ -- union介绍
- Java核心API需要掌握的程度
- QT——设置可执行文件图标
- HTML中利用堆栈方式对Table进行行排序
- 【clickhouse】clickhouse 利用Grafana与系统表监控ClickHouse查询
- Python核心编程读笔 4
- 华硕触控板无法在Win11中使用的解决办法
- 我的2019全年目标
- VS 用户自定义控件未出现在工具箱的解决方案
- KubeEdge Node not ready
- 自定义函数fac1用递推方法求n!,自定义函数fac2用递归方法求n!,主函数中输入整数n(0≦n≦10)后,分别调用函数fac1和函数fac2求n!,最后输出调用的结果值进行对比。
- 跟我学Python图像处理丨图像特效处理:毛玻璃、浮雕和油漆特效
- 信息安全系统设计基础期中总结
- JavaScript使用事件onclick导致css样式失效问题
- 2021-05-08 小华子第一篇
- 全志T507如何在Android系统上进行OTA升级
- Gnome Shell Themes 推荐 Flat-Plat-Blue
热门文章
- FPGA系统性学习笔记连载_Day7【16位比较器设计】 【原理及verilog实现、仿真】篇
- abc计算机发明英语翻译,英语四级翻译模拟练习:四大发明
- 单独某个设置feign接口的超时时间
- Javaweb+mysql校园二手平台(用户设置、发布信息、信息管理、搜索信息,留言,及系统管理)
- typescript基础学习
- cppcheck使用指南
- 赵匡胤为何不把皇位传给儿子却传弟弟赵光义
- linux dc命令,Linux中dc命令起什么作用呢?
- g4600支持服务器内存吗,Intel奔腾G4560和G4600哪个好?秒懂G4560和G4600区别 (全文)
- 深度学习100例-循环神经网络(LSTM)实现股票预测 | 第10天