分享

Android 4.0 Launcher2源码分析

 quasiceo 2015-11-14
分类: Android 2013-08-20 20:11 1240人阅读 评论(0) 收藏 举报

最近开始接触Android,并且需要改造Android的原生Laucher。

第一步,需要先对Laucher界面元素进行分析,以便进一步的学习和了解。


本文来自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中的结构:


  1. <com.android.launcher2.DragLayer  
  2.     xmlns:android="http://schemas./apk/res/android"  
  3.     xmlns:launcher="http://schemas./apk/res/com.android.launcher"  
  4.     android:id="@+id/drag_layer"  
  5.     ...  
  6.     >  
  7.   
  8.   
  9.     <!-- Keep these behind the workspace so that they are not visible when  
  10.          we go into AllApps -->  
  11.     <include  
  12.         android:id="@+id/dock_divider"  
  13.     layout="@layout/workspace_divider"  
  14.         ...  
  15.      />  
  16.   
  17.   
  18.     <!-- 分页指示器 -->  
  19.     <include  
  20.         android:id="@+id/paged_view_indicator"  
  21.         layout="@layout/scroll_indicator"  
  22.         ...  
  23.      />  
  24.   
  25.   
  26.     <!-- The workspace contains 5 screens of cells -->  
  27.     <com.android.launcher2.Workspace  
  28.         android:id="@+id/workspace"  
  29.         ...  
  30.         >  
  31.   
  32.   
  33.         <!-- 五个分屏,默认显示cell3 -->  
  34.         <include android:id="@+id/cell1" layout="@layout/workspace_screen" />  
  35.         <include android:id="@+id/cell2" layout="@layout/workspace_screen" />  
  36.         <include android:id="@+id/cell3" layout="@layout/workspace_screen" />  
  37.         <include android:id="@+id/cell4" layout="@layout/workspace_screen" />  
  38.         <include android:id="@+id/cell5" layout="@layout/workspace_screen" />  
  39.     </com.android.launcher2.Workspace>  
  40.   
  41.   
  42.     <!-- 搜索框/删除框 -->  
  43.     <include  
  44.         android:id="@+id/qsb_bar"  
  45.         layout="@layout/qsb_bar" />  
  46.   
  47.   
  48.     <!-- 显示具体全部应用的界面,包括APPS、WIGHETS的tab标签,以及显示ALL APP的页面和现实APP WIGHETS的页面 -->  
  49.     <include layout="@layout/apps_customize_pane"  
  50.         android:id="@+id/apps_customize_pane"  
  51.         ..  
  52.     />  
  53.   
  54.   
  55.     <!-- WorkSpace最下面的五个快捷位置 -->  
  56.     <include layout="@layout/hotseat"  
  57.         android:id="@+id/hotseat"  
  58.         ..  
  59.      />  
  60.   
  61.   
  62.     <!-- 刚启动的时候显示的指导页 -->  
  63.     <include layout="@layout/workspace_cling"  
  64.         android:id="@+id/workspace_cling"  
  65.         ...  
  66.     />  
  67.   
  68.   
  69.     <!-- 是第一次进入全部应用之后显示的指导页 -->  
  70.     <include layout="@layout/folder_cling"  
  71.         android:id="@+id/folder_cling"  
  72.         ...  
  73.     />  
  74. </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,效果如下:

workspace显示的效果

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

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

删除框搜索框

7、id/apps_customize_pane,效果如下

apps_customize_pane

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

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


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


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


0
0

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多