本文来自 http://blog.csdn.net/chenshaoyang0011 转载请申明文章出处!

Android系统的一大特色是它拥有的桌面通知系统,不同于IOS的桌面管理,Android有一个桌面系统用于管理和展示APP以及桌面Widget等。Android提供一个默认的桌面应

用,当然我们也可以使用第三方的桌面应用。Android的Launcher的源码在 \packages\apps\Launcher2。Launcher2的主布局文件包括res\layout-land\launcher.xml

,res\layout-port\launcher.xml ,res\layout-sw600dp\launcher.xml ,分别适配横屏,竖屏和7寸平板。内容大同小异,这里就以res\layout-port\launcher.xml的为例。

首先让我们看看launcher.xml中的结构:

[html] view plain copy
  1. <com.android.launcher2.DragLayer
  2. xmlns:android="http://schemas.android.com/apk/res/android"
  3. xmlns:launcher="http://schemas.android.com/apk/res/com.android.launcher"
  4. android:id="@+id/drag_layer"
  5. ...
  6. >
  7. <!--Keepthesebehindtheworkspacesothattheyarenotvisiblewhen
  8. wegointoAllApps-->
  9. <include
  10. android:id="@+id/dock_divider"
  11. layout="@layout/workspace_divider"
  12. ...
  13. />
  14. <!--分页指示器-->
  15. <include
  16. android:id="@+id/paged_view_indicator"
  17. layout="@layout/scroll_indicator"
  18. ...
  19. />
  20. <!--Theworkspacecontains5screensofcells-->
  21. <com.android.launcher2.Workspace
  22. android:id="@+id/workspace"
  23. ...
  24. >
  25. <!--五个分屏,默认显示cell3-->
  26. <includeandroid:id="@+id/cell1"layout="@layout/workspace_screen"/>
  27. <includeandroid:id="@+id/cell2"layout="@layout/workspace_screen"/>
  28. <includeandroid:id="@+id/cell3"layout="@layout/workspace_screen"/>
  29. <includeandroid:id="@+id/cell4"layout="@layout/workspace_screen"/>
  30. <includeandroid:id="@+id/cell5"layout="@layout/workspace_screen"/>
  31. </com.android.launcher2.Workspace>
  32. <!--搜索框/删除框-->
  33. <include
  34. android:id="@+id/qsb_bar"
  35. layout="@layout/qsb_bar"/>
  36. <!--显示具体全部应用的界面,包括APPS、WIGHETS的tab标签,以及显示ALLAPP的页面和现实APPWIGHETS的页面-->
  37. <includelayout="@layout/apps_customize_pane"
  38. android:id="@+id/apps_customize_pane"
  39. ..
  40. />
  41. <!--WorkSpace最下面的五个快捷位置-->
  42. <includelayout="@layout/hotseat"
  43. android:id="@+id/hotseat"
  44. ..
  45. />
  46. <!--刚启动的时候显示的指导页-->
  47. <includelayout="@layout/workspace_cling"
  48. android:id="@+id/workspace_cling"
  49. ...
  50. />
  51. <!--是第一次进入全部应用之后显示的指导页-->
  52. <includelayout="@layout/folder_cling"
  53. android:id="@+id/folder_cling"
  54. ...
  55. />
  56. </com.android.launcher2.DragLayer>

接着我们来一一认识每一个View控件。

1、最外层的DragLayer,是一个继承自FramLayout的View控件,显示的就是整个桌面根容器。桌面的所有控件都是位于DragLayer中。

2、id/dock_divider,使用了布局workspace_divider,其实就是一个ImageView。是Workspace与Hotseat之间的分割线。

workspace_divider显示的效果

3、id/paged_view_indicator,使用了布局scroll_indicator,显示效果是在id/dock_divider上显示一条淡蓝色的横线,来指示当分屏所处的位置

4、id/workspace ,工作空间拥有五个workspace_screen,即有五个分屏,每个分屏都可以放置shortcut和AppWidget,效果如下:

Android 4.0 Launcher2源码分析——主布局文件_第1张图片

5、id/cell1..cell5 ,分别代表五个分屏

6、id/qsb_bar 搜索框/删除框,根据需要进行切换

删除框 搜索框

7、id/apps_customize_pane,效果如下

Android 4.0 Launcher2源码分析——主布局文件_第2张图片

8、id/hotseat 即主屏幕下方的五个快捷位置

9、id/workspace_cling当第一次运行Launcher2时,会显示的用于指导的动画,以后不再显示

Android 4.0 Launcher2源码分析——主布局文件_第3张图片Android 4.0 Launcher2源码分析——主布局文件_第4张图片

10、id/folder_cling,第一次使用Folder时,展示给用户的指导画面。

Android 4.0 Launcher2源码分析——主布局文件_第5张图片

这样,我们已经可以使每个UI界面及组件都对号入座,这会使接下来分析的时候更加清晰。

更多相关文章

  1. RelativeLayout的一些布局属性
  2. 源码茶舍之android:externalService是什么属性?实现原理?
  3. Android的消息处理机制(深入源码)
  4. Android内核源码阅读---ashmem.c
  5. 基于 Android NDK 的学习之旅----- C调用Java(附源码)
  6. Android中布局属性(如android:drawableBottom等)的作用总结
  7. Android中的资源布局

随机推荐

  1. Google 有了Android,为何还要Chrome OS
  2. Android疯狂的专利战争史记
  3. [Android] 给图像添加相框、圆形圆角显示
  4. Android RSS阅读器
  5. Android中AsyncTask(异步任务)详解
  6. Android(安卓)ListView工作原理完全解析,
  7. 保持Android手机屏幕长亮
  8. Android中如何禁止音量调节至静音
  9. 安卓系统上的远程 JS 调试 Remote JavaSc
  10. android/ios行驶证识别保险行业应用