最近在研究Lanucher,看了源码,发现了SlidingDrawer这个类,也就是所谓的"抽屉"类。它的用法很简单,要包括handle,和content.

handle就是当你点击它的时候,content要么抽抽屉要么关抽屉。别的不多说了,具体步骤如下.

1.新建Android工程,命名为SlidingDrawer.

2.准备素材,在这里我的图标是用Launcher2里面的图标,放在drawable-hdpi文件夹目录结构如下:

3.设置main.xml布局:代码如下:

[java] view plain copy
  1. <?xmlversion="1.0"encoding="utf-8"?>
  2. <LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"
  3. android:orientation="vertical"
  4. android:layout_width="fill_parent"
  5. android:layout_height="fill_parent"
  6. android:background="#808080"
  7. >
  8. <SlidingDrawer
  9. android:id="@+id/slidingdrawer"
  10. android:layout_width="fill_parent"
  11. android:layout_height="fill_parent"
  12. android:orientation="vertical"
  13. android:handle="@+id/handle"
  14. android:content="@+id/content">
  15. <Button
  16. android:id="@+id/handle"
  17. android:layout_width="88dip"
  18. android:layout_height="44dip"
  19. android:background="@drawable/handle"
  20. />
  21. <LinearLayout
  22. android:id="@+id/content"
  23. android:layout_width="fill_parent"
  24. android:layout_height="fill_parent"
  25. android:background="#00ff00">
  26. <Button
  27. android:id="@+id/button"
  28. android:layout_width="wrap_content"
  29. android:layout_height="wrap_content"
  30. android:text="Button"
  31. />
  32. <EditText
  33. android:id="@+id/editText"
  34. android:layout_width="fill_parent"
  35. android:layout_height="wrap_content"
  36. />
  37. </LinearLayout>
  38. </SlidingDrawer>
  39. </LinearLayout>

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

[java] view plain copy
  1. <?xmlversion="1.0"encoding="utf-8"?>
  2. <selectorxmlns:android="http://schemas.android.com/apk/res/android">
  3. <itemandroid:state_window_focused="false"android:state_enabled="true"android:drawable="@drawable/handle_normal"/>
  4. <itemandroid:state_pressed="true"android:drawable="@drawable/handle_pressed"/>
  5. <itemandroid:state_focused="true"android:state_enabled="true"android:drawable="@drawable/handle_focused"/>
  6. <itemandroid:state_enabled="true"android:drawable="@drawable/handle_normal"/>
  7. <itemandroid:state_focused="true"android:drawable="@drawable/handle_focused"/>
  8. </selector>

5.运行之。将会得到如下效果:

的比较简单呵呵,如果想深入了解,大家看Launcher源码吧!


更多相关文章

  1. Android入门第十一篇之TabHost,TabWidget
  2. android第一天学习基本配置与安装过程和启动
  3. android开发之Seekbar
  4. Android(安卓)SQLiteOpenHelper源码解读
  5. Android使用GridView实现俄罗斯方块(附源码)(一)
  6. 【Android源码】Android(安卓)UI 之一步步教你自定义控件
  7. Android仿今日头条和知乎等App顶部滑动导航实现代码分析及源码下
  8. Android(安卓)获取未安装的APK图标
  9. Android设计模式系列(8)--SDK源码之工厂方法模式

随机推荐

  1. android下变态的串口通讯
  2. Android学习札记26:深入理解Android中的消
  3. Android中转义字符
  4. Android日记之2012/02/12——Android中正
  5. Android学习之期末复习重点整理
  6. Android 中判断网络连接和GPS是否可用及H
  7. Android Building System 总结
  8. Computex 2011:展示可在Windows 7底下运作
  9. android应用开发总论
  10. 致Android初学者:如何学习Android开发