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

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

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

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

Android高手进阶教程(二)之----Android Launcher抽屉类SlidingDrawer的使用_第1张图片

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

view plain
  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,代码如下:

view plain
  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.运行之。将会得到如下效果:

Android高手进阶教程(二)之----Android Launcher抽屉类SlidingDrawer的使用_第2张图片

Android高手进阶教程(二)之----Android Launcher抽屉类SlidingDrawer的使用_第3张图片

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


更多相关文章

  1. Android高手进阶教程(二十二)之Android中几种图像特效处理的集锦
  2. android修炼进阶之法
  3. Android高手进阶教程(十六)---Android中Intent传递对象的两种方
  4. 最新Android Studio更换应用图标方法

随机推荐

  1. (详解)Eclipse3.6搭建 Android 2.2 开发
  2. 亚马逊面向开发人员推出Android应用商店
  3. Android面试及开发忠告
  4. 2011届 实训总结
  5. Android的三个阶段
  6. [置顶] 【Android】开源 闲暇(Leisure)
  7. ClassLoader解析——Android篇
  8. Android RIL
  9. Android 开发中的日常积累
  10. Android黑科技动态加载(三)之动态加载资