Launcher源码浅析-----Launcher布局

来源:互联网 发布:网络特性怎么做营销 编辑:程序博客网 时间:2024/05/22 11:55

怕以后找不到,转载过来,原博为:http://blog.csdn.net/stevenhu_223/article/details/9842115

====================================================================================================================================

   前言:Launcher是Android的系统应用,在手机开机后第一个见到就是Launcher。用户通过Launcher基本上可以从整体上纵观手机中所存在的所有应用;Android源码中的Launcher分两个主要界面,一个是WorkSpace界面,就是我们俗称的桌面;另一个是AppsCustomizePagedView界面,就是我们俗称的菜单界面;Launcher可以说是Android系统中比较重要的系统应用模块,能够掌握和熟悉Launcher模块,当然是最好的,Launcher这块骨头很硬,必须要慢慢啃;个人认为,在熟悉一个系统模块之前,弄清楚它的整体布局是至关重要的,所以这篇文章主要是重点分析Launcher的相关布局,若有不当之处,还请同行们指点迷津。废话有点多了,开始吧!

   一. Launcher主入口

       Launcher就是一个系统应用, 如果想要知道Launcher中都有那些四大组件和主入口,那么通过它的AndroidManifest.xml文件代码就可以探知,如下:

[html] view plaincopy
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <manifest  
  3.     xmlns:android="http://schemas.android.com/apk/res/android"  
  4.     package="com.android.launcher">  
  5.   
  6.     <original-package android:name="com.android.launcher2" />  
  7.   
  8.     <!-- Launcher中自定义的权限 -->  
  9.     <permission  
  10.         android:name="com.android.launcher.permission.INSTALL_SHORTCUT"  
  11.         android:permissionGroup="android.permission-group.SYSTEM_TOOLS"  
  12.         android:protectionLevel="normal"  
  13.         android:label="@string/permlab_install_shortcut"  
  14.         android:description="@string/permdesc_install_shortcut" />  
  15.     <permission  
  16.         android:name="com.android.launcher.permission.UNINSTALL_SHORTCUT"  
  17.         android:permissionGroup="android.permission-group.SYSTEM_TOOLS"  
  18.         android:protectionLevel="normal"  
  19.         android:label="@string/permlab_uninstall_shortcut"  
  20.         android:description="@string/permdesc_uninstall_shortcut"/>  
  21.     <permission  
  22.         android:name="com.android.launcher.permission.READ_SETTINGS"  
  23.         android:permissionGroup="android.permission-group.SYSTEM_TOOLS"  
  24.         android:protectionLevel="normal"  
  25.         android:label="@string/permlab_read_settings"  
  26.         android:description="@string/permdesc_read_settings"/>  
  27.     <permission  
  28.         android:name="com.android.launcher.permission.WRITE_SETTINGS"  
  29.         android:permissionGroup="android.permission-group.SYSTEM_TOOLS"  
  30.         android:protectionLevel="normal"  
  31.         android:label="@string/permlab_write_settings"  
  32.         android:description="@string/permdesc_write_settings"/>  
  33.   
  34.     <!-- 注册系统权限 -->  
  35.     <uses-permission android:name="android.permission.CALL_PHONE" />  
  36.     <uses-permission android:name="android.permission.SET_WALLPAPER" />  
  37.     <uses-permission android:name="android.permission.SET_WALLPAPER_HINTS" />  
  38.     <uses-permission android:name="android.permission.VIBRATE" />  
  39.     <uses-permission android:name="android.permission.BIND_APPWIDGET" />  
  40.     <uses-permission android:name="com.android.launcher.permission.READ_SETTINGS" />  
  41.     <uses-permission android:name="com.android.launcher.permission.WRITE_SETTINGS" />  
  42.   
  43.     <!-- hardwareAccelerated为是否使用硬件加速,largeHeap为是否使用了大的堆内存,值在config.xml文件中定义 -->  
  44.     <application  
  45.         android:name="com.android.launcher2.LauncherApplication"  
  46.         android:label="@string/application_name"  
  47.         android:icon="@drawable/ic_launcher_home"  
  48.         android:hardwareAccelerated="@bool/config_hardwareAccelerated"  
  49.         android:largeHeap="@bool/config_largeHeap">  
  50.         <activity  
  51.             android:name="com.android.launcher2.Launcher"  
  52.             android:launchMode="singleTask"  
  53.             android:clearTaskOnLaunch="true"  
  54.             android:stateNotNeeded="true"  
  55.             android:theme="@style/Theme"  
  56.             android:windowSoftInputMode="adjustPan"  
  57.             android:screenOrientation="nosensor">  
  58.             <intent-filter>  
  59.                 <action android:name="android.intent.action.MAIN" />  
  60.                 <category android:name="android.intent.category.HOME" />  
  61.                 <category android:name="android.intent.category.DEFAULT" />  
  62.                 <category android:name="android.intent.category.MONKEY"/>  
  63.             </intent-filter>  
  64.         </activity>  
  65.   
  66.         <activity  
  67.             android:name="com.android.launcher2.WallpaperChooser"  
  68.             style="@style/Theme.WallpaperPicker"  
  69.             android:label="@string/pick_wallpaper"  
  70.             android:icon="@drawable/ic_launcher_wallpaper"  
  71.             android:finishOnCloseSystemDialogs="true"  
  72.             android:process=":wallpaper_chooser">  
  73.             <intent-filter>  
  74.                 <action android:name="android.intent.action.SET_WALLPAPER" />  
  75.                 <category android:name="android.intent.category.DEFAULT" />  
  76.             </intent-filter>  
  77.             <meta-data android:name="android.wallpaper.preview"  
  78.                 android:resource="@xml/wallpaper_picker_preview" />  
  79.         </activity>  
  80.   
  81.         <activity android:name="com.android.launcher2.RocketLauncher"  
  82.             android:label="@string/dream_name"  
  83.             android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen">  
  84.             <intent-filter>  
  85.                 <action android:name="android.intent.action.MAIN" />  
  86.                 <category android:name="android.intent.category.DEFAULT" />  
  87.                 <category android:name="android.intent.category.DREAM" />  
  88.             </intent-filter>  
  89.         </activity>  
  90.   
  91.         <!-- Intent received used to install shortcuts from other applications -->  
  92.         <receiver  
  93.             android:name="com.android.launcher2.InstallShortcutReceiver"  
  94.             android:permission="com.android.launcher.permission.INSTALL_SHORTCUT">  
  95.             <intent-filter>  
  96.                 <action android:name="com.android.launcher.action.INSTALL_SHORTCUT" />  
  97.             </intent-filter>  
  98.         </receiver>  
  99.   
  100.         <!-- Intent received used to uninstall shortcuts from other applications -->  
  101.         <receiver  
  102.             android:name="com.android.launcher2.UninstallShortcutReceiver"  
  103.             android:permission="com.android.launcher.permission.UNINSTALL_SHORTCUT">  
  104.             <intent-filter>  
  105.                 <action android:name="com.android.launcher.action.UNINSTALL_SHORTCUT" />  
  106.             </intent-filter>  
  107.         </receiver>  
  108.   
  109.         <!-- The settings provider contains Home's data, like the workspace favorites -->  
  110.         <provider  
  111.             android:name="com.android.launcher2.LauncherProvider"  
  112.             android:authorities="com.android.launcher2.settings"  
  113.             android:writePermission="com.android.launcher.permission.WRITE_SETTINGS"  
  114.             android:readPermission="com.android.launcher.permission.READ_SETTINGS" />  
  115.   
  116.     </application>  
  117. </manifest>  

        通过AndroidManifest.xm文件中的代码可以知道:

         1). com.android.launcher2.LauncherApplication类描述整个应用,该类继承Application。某种意义上来说是Launcher的主入口类;在Launcher应用创建时,最先执行的是LauncherApplication类中的onCreate()方法;LauncherApplication类中主要实现注册一些广播接收器和监听数据库改变的ContentObserver,同时对外(主要是主Activity)提供一些获取相关对象(LauncherModel、IconCache、LauncherProvider等)和屏幕密度的接口函数。

         2). com.android.launcher2.Launcher为Launcher模块的主Activity,Launcher中的灵魂类。在该主Activity的onCreate方法中执行setContentView(R.layout.launcher)加载Launcher的整个布局。

         3). com.android.launcher2.WallpaperChooser为长按桌面空白处弹出的选择壁纸相关的Activity组件。

         4).com.android.launcher2.InstallShortcutReceiver为安装快捷方式时负责接收相关广播进行操作的BroadcastReceiver组件。比如,要为自己开发的应用添加第一次启动时在桌面创建快捷键的功能,那么就需要注册com.android.launcher.permission.INSTALL_SHORTCUT权限,同时发送Intent的Action为com.android.launcher.action.INSTALL_SHORTCUT的广播。

         5). com.android.launcher2.UninstallShortcutReceiver为卸载快捷方式时负责接收相关广播进行操作的BroadcastReceiver组件。

         7). com.android.launcher2.LauncherProvider为Launcher进行数据库相关操作的ContentProvider组件。

   二. Launcher总布局文件launcher.xml浅析

       通过上文的介绍,可以知道,布局文件launcher.xml是在Launcher的onCreate方法中加载的。

       1. Launcher.xml文件代码(竖向布局):

[html] view plaincopy
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <com.android.launcher2.DragLayer  
  3.     xmlns:android="http://schemas.android.com/apk/res/android"  
  4.     xmlns:launcher="http://schemas.android.com/apk/res/com.android.launcher"  
  5.   
  6.     android:id="@+id/drag_layer"  
  7.     android:layout_width="match_parent"  
  8.     android:layout_height="match_parent">  
  9.   
  10.     <!-- Keep these behind the workspace so that they are not visible when  
  11.          we go into AllApps -->  
  12.     <!-- dock_divider为桌面分隔线,将hotseat和Workspace分隔 -->  
  13.     <include  
  14.         android:id="@+id/dock_divider"  
  15.         layout="@layout/workspace_divider"  
  16.         android:layout_width="match_parent"  
  17.         android:layout_height="wrap_content"  
  18.         android:layout_marginBottom="@dimen/button_bar_height"  
  19.         android:layout_gravity="bottom" />  
  20.     <!-- 桌面分隔线的上指示条,Workspace翻页的时候显示 -->  
  21.     <include  
  22.         android:id="@+id/paged_view_indicator"  
  23.         layout="@layout/scroll_indicator"  
  24.         android:layout_width="wrap_content"  
  25.         android:layout_height="wrap_content"  
  26.         android:layout_gravity="bottom"  
  27.         android:layout_marginBottom="@dimen/button_bar_height" />  
  28.   
  29.     <!-- The workspace contains 5 screens of cells -->  
  30.     <!-- Workspace即手机桌面,默认系统是包含可翻转5页 -->  
  31.     <com.android.launcher2.Workspace  
  32.         android:id="@+id/workspace"  
  33.         android:layout_width="match_parent"  
  34.         android:layout_height="match_parent"  
  35.         android:paddingTop="@dimen/qsb_bar_height_inset"  
  36.         android:paddingBottom="@dimen/button_bar_height"  
  37.         launcher:defaultScreen="2"  
  38.         launcher:cellCountX="4"  
  39.         launcher:cellCountY="4"  
  40.         launcher:pageSpacing="@dimen/workspace_page_spacing"  
  41.         launcher:scrollIndicatorPaddingLeft="@dimen/workspace_divider_padding_left"  
  42.         launcher:scrollIndicatorPaddingRight="@dimen/workspace_divider_padding_right">  
  43.   
  44.         <!-- Workspace总共可翻转5个页面,一个 workspace_screen定义一个页面布局-->  
  45.         <include android:id="@+id/cell1" layout="@layout/workspace_screen" />  
  46.         <include android:id="@+id/cell2" layout="@layout/workspace_screen" />  
  47.         <include android:id="@+id/cell3" layout="@layout/workspace_screen" />  
  48.         <include android:id="@+id/cell4" layout="@layout/workspace_screen" />  
  49.         <include android:id="@+id/cell5" layout="@layout/workspace_screen" />  
  50.     </com.android.launcher2.Workspace>  
  51.   
  52.     <!-- qsb_bar布局包含桌面上的可搜索框 以及长按桌面上图标时显示删除和应用信息的操作框-->  
  53.     <include  
  54.         android:id="@+id/qsb_bar"  
  55.         layout="@layout/qsb_bar" />  
  56.   
  57.     <!-- 点击hotseat中心图标进入的界面,该界面显示所有应用和小部件 -->  
  58.     <include layout="@layout/apps_customize_pane"  
  59.         android:id="@+id/apps_customize_pane"  
  60.         android:layout_width="match_parent"  
  61.         android:layout_height="match_parent"  
  62.         android:visibility="invisible" />  
  63.   
  64.     <!-- hotseat为桌面分隔线下的界面, 不随Workspace翻页操作而移动 -->  
  65.     <include layout="@layout/hotseat"  
  66.         android:id="@+id/hotseat"  
  67.         android:layout_width="match_parent"  
  68.         android:layout_height="@dimen/button_bar_height_plus_padding"  
  69.         android:layout_gravity="bottom" />  
  70.   
  71.     <!-- 手机刚开机,或者对launcher应用清空数据第一次进入到workspace时弹出的操作介绍界面 -->  
  72.     <include layout="@layout/workspace_cling"  
  73.         android:id="@+id/workspace_cling"  
  74.         android:layout_width="match_parent"  
  75.         android:layout_height="match_parent"  
  76.         android:visibility="gone" />  
  77.   
  78.     <!-- 手机刚开机,或者对launcher应用清空数据,第一次打开将workspace上两个以上的图标拖到一起形成 的文件夹时弹出的操作界面-->  
  79.     <include layout="@layout/folder_cling"  
  80.         android:id="@+id/folder_cling"  
  81.         android:layout_width="match_parent"  
  82.         android:layout_height="match_parent"  
  83.         android:visibility="gone" />  
  84. </com.android.launcher2.DragLayer>  

    2. 以下列出Launcher主要界面的截图:

         

                       图1                                                     图2                                              图3

  上面三个图比较直观的说明Launcher的主要布局:

     图1:Launcher的桌面布局(从上到下为搜索框、Workspace、分割线、hotseat)。

     图2:菜单界面(apps_customize_pane)之一的显示所有已安装的应用程序;

     图3:菜单界面(apps_customize_pane)之一的显示所有已创建的widget(小部件)

     注:菜单界面整体是一个TabHost,由两个子Tab组成;一个就是显示图2界面的子Tab,另一个就是显示图3界面的子Tab

  3. 从上到下分析Launcher.xml文件中的代码:

     1). 整个树状布局的最上层是com.android.launcher2.DragLayer,DragLayer类继承自FrameLayout,属于自定义实现的ViewGroup类型容器视图组件。DragLayer类中主要负责Launcher中相关的拖拽处理;

     2).id为dock_divider的子视图(分割线):通过< include />元素添加布局为workspace_divider(对应的布局),我们到workspace_divider.xml文件看看该子视图的真正布局,如下:

        workspace_divider.xml代码:

[html] view plaincopy
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <ImageView  
  3.     xmlns:android="http://schemas.android.com/apk/res/android"  
  4. xmlns:launcher="http://schemas.android.com/apk/res/com.android.launcher"  
  5.     android:paddingLeft="@dimen/workspace_divider_padding_left"  
  6.     android:paddingRight="@dimen/workspace_divider_padding_right"  
  7.     android:paddingTop="@dimen/workspace_divider_padding_top"  
  8.     android:paddingBottom="@dimen/workspace_divider_padding_bottom"  
  9.     android:scaleType="fitXY"  
  10.     android:src="@drawable/hotseat_track_holo" />  

         由此可知id为dock_divider的子视图就是一个ImageView对象,即一条点9图的分割线;该分割线把Workspace和Hotseat分割出来;

     3). id为paged_view_indicator的子视图:该子视图对应布局为scroll_indicator,scroll_indicator.xml文件的代码如下:

[html] view plaincopy
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <ImageView  
  3.     xmlns:android="http://schemas.android.com/apk/res/android"  
  4.     xmlns:launcher="http://schemas.android.com/apk/res/com.android.launcher"  
  5.     android:visibility="gone"  
  6.     android:alpha="0"  
  7.     android:scaleType="fitXY"  
  8.     android:src="@drawable/hotseat_scrubber_holo" />  
      所以,该视图也为ImageView对象,即一个点9图的蓝色指示线,当我们在桌面上滑动翻页时,该蓝色指示线会显示,用于指示翻页操作;

      4). id为workspace的子视图(Workspace界面视图):该子视图为自定义类Workspace,Workspace继承自SmoothPagedView,SmoothPagedView继承自PagedView,PagedView继承自ViewGroup;所以Workspace的终极父类也是ViewGroup;即该子视图为ViewGroup类型的自定义容器视图;在Workspace视图中又包含了5个id分别为cell1、cell2、cell3、cell4、cell5的子视图。它们对应的布局均为workspace_screen,workspace_screen.xml文件的代码如下:

[html] view plaincopy
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <com.android.launcher2.CellLayout  
  3.     xmlns:android="http://schemas.android.com/apk/res/android"  
  4.     xmlns:launcher="http://schemas.android.com/apk/res/com.android.launcher"  
  5.     style="@style/WorkspaceScreen"  
  6.   
  7.     android:paddingLeft="@dimen/workspace_left_padding"  
  8.     android:paddingRight="@dimen/workspace_right_padding"  
  9.     android:paddingTop="@dimen/workspace_top_padding"  
  10.     android:paddingBottom="@dimen/workspace_bottom_padding"  
  11.     android:hapticFeedbackEnabled="false"  
  12.   
  13.     launcher:cellWidth="@dimen/workspace_cell_width"  
  14.     launcher:cellHeight="@dimen/workspace_cell_height"  
  15.     launcher:widthGap="@dimen/workspace_width_gap"  
  16.     launcher:heightGap="@dimen/workspace_height_gap"  
  17.     launcher:maxGap="@dimen/workspace_max_gap" />  
      所以,Workspace中包含的五个子视图均为自定义视图类CellLayout(CellLayout继承ViewGroup);一个CellLayout对应Workspace中的一页(一屏),Workspace中默认情况下总共可翻转5页,所以Workspace中有5个CellLayout(cell1、cell2、cell3、cell4、cell5);Workspace的区域就是图1中位于搜索框和分割线之间的区域;

      5). id为qsb_bar的子视图:该子视图对应的布局为qsb_bar,布局文件qsb_bar.xml的代码如下:

[html] view plaincopy
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <com.android.launcher2.SearchDropTargetBar  
  3.     xmlns:android="http://schemas.android.com/apk/res/android"  
  4.     xmlns:launcher="http://schemas.android.com/apk/res/com.android.launcher"  
  5.     style="@style/QSBBar"  
  6.     android:focusable="false"  
  7.     android:background="@drawable/search_bg_panel">  
  8.   
  9.     <!-- Search buttons container -->  
  10.     <!-- 桌面上可点击的搜索框 -->  
  11.     <include android:id="@+id/qsb_search_bar"  
  12.         layout="@layout/search_bar" />  
  13.   
  14.     <!-- Drag specific targets container -->  
  15.       
  16.     <!-- 长按菜单界面快捷图标进入到桌面时显示删除和应用信息的操作框,这时候搜索框会隐藏,操作框会显示在 搜索框的位置-->  
  17.     <LinearLayout  
  18.         style="@style/SearchDropTargetBar"  
  19.         android:id="@+id/drag_target_bar"  
  20.         android:visibility="gone">  
  21.   
  22.         <!-- 显示删除的布局 -->  
  23.         <FrameLayout  
  24.             style="@style/DropTargetButtonContainer"  
  25.             android:layout_weight="1">  
  26.             <!-- Delete target -->  
  27.             <com.android.launcher2.DeleteDropTarget  
  28.                 style="@style/DropTargetButton"  
  29.                 android:id="@+id/delete_target_text"  
  30.                 android:text="@string/delete_zone_label_workspace"  
  31.                 android:drawableLeft="@drawable/delete_target_selector" />  
  32.         </FrameLayout>  
  33.   
  34.         <!-- 显示应用信息的布局 -->  
  35.         <FrameLayout  
  36.             style="@style/DropTargetButtonContainer"  
  37.             android:layout_weight="1">  
  38.             <!-- Info target -->  
  39.             <com.android.launcher2.InfoDropTarget  
  40.                 style="@style/DropTargetButton"  
  41.                 android:id="@+id/info_target_text"  
  42.                 android:text="@string/info_target_label"  
  43.                 android:drawableLeft="@drawable/info_target_selector" />  
  44.         </FrameLayout>  
  45.     </LinearLayout>  
  46.       
  47. </com.android.launcher2.SearchDropTargetBar>  
    该子视图的布局包含搜索框的视图布局和操作框的视图布局:

      -->搜索框对应的是id为qsb_search_bar的视图,它对应的布局文件为search_bar.xml;

      -->操作框对应的是id为drag_target_bar的视图(LinearLayout),操作框包含两部分(两个FrameLayout):一部分对应的是id为delete_target_text的布局(DeleteDropTarget),拖拽应用图标至该区域时会进入卸载应用的操作;另一部分对应的是id为info_target_text的布局(InfoDropTarget),拽应用图标至该区域时会进入显示应用程序信息的界面;如下图就是从菜单拖拽应用图标到桌面是操作框显示的示意图(屏幕上方显示操作框):

     

      6). id为apps_customize_pane的子视图(菜单界面视图):该子视图对应的布局为apps_customize_pane,apps_customize_pane文件代码如下:

[html] view plaincopy
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <!-- 点击hotseat中心图标显示的菜单界面布局,该界面显示所有应用和小部件 -->  
  3. <com.android.launcher2.AppsCustomizeTabHost  
  4.     xmlns:android="http://schemas.android.com/apk/res/android"  
  5.     xmlns:launcher="http://schemas.android.com/apk/res/com.android.launcher"  
  6.     android:background="#FF000000">  
  7.     <LinearLayout  
  8.         android:orientation="vertical"  
  9.         android:layout_width="match_parent"  
  10.         android:layout_height="match_parent">  
  11.         <!-- The layout_width of the tab bar gets overriden to align the content  
  12.              with the text in the tabs in AppsCustomizeTabHost. -->  
  13.         <!-- Tab标签"应用程序"、"窗口小部件"和应用商店图标的视图布局 -->  
  14.         <FrameLayout  
  15.             android:id="@+id/tabs_container"  
  16.             android:layout_width="wrap_content"  
  17.             android:layout_height="@dimen/apps_customize_tab_bar_height"  
  18.             android:layout_gravity="center_horizontal">  
  19.             <com.android.launcher2.FocusOnlyTabWidget  
  20.                 android:id="@android:id/tabs"  
  21.                 android:layout_width="match_parent"  
  22.                 android:layout_height="match_parent"  
  23.                 android:layout_gravity="left"  
  24.                 android:background="@drawable/tab_unselected_holo"  
  25.                 android:tabStripEnabled="false" />  
  26.             <include  
  27.                 android:id="@+id/market_button"  
  28.                 layout="@layout/market_button"  
  29.                 android:layout_width="wrap_content"  
  30.                 android:layout_height="match_parent"  
  31.                 android:layout_gravity="right" />  
  32.         </FrameLayout>  
  33.         <FrameLayout  
  34.             android:id="@android:id/tabcontent"  
  35.             android:layout_width="match_parent"  
  36.             android:layout_height="match_parent">  
  37.             <!-- 承载所有应用程序图标和widget的视图布局 -->  
  38.             <com.android.launcher2.AppsCustomizePagedView  
  39.                 android:id="@+id/apps_customize_pane_content"  
  40.                 android:layout_width="match_parent"  
  41.                 android:layout_height="match_parent"  
  42.                 launcher:cellCountX="@integer/apps_customize_cellCountX"  
  43.                 launcher:cellCountY="@integer/apps_customize_cellCountY"  
  44.                 launcher:pageLayoutWidthGap="@dimen/apps_customize_pageLayoutWidthGap"  
  45.                 launcher:pageLayoutHeightGap="@dimen/apps_customize_pageLayoutHeightGap"  
  46.                 launcher:pageLayoutPaddingTop="@dimen/apps_customize_pageLayoutPaddingTop"  
  47.                 launcher:pageLayoutPaddingBottom="@dimen/apps_customize_pageLayoutPaddingBottom"  
  48.                 launcher:pageLayoutPaddingLeft="@dimen/apps_customize_pageLayoutPaddingLeft"  
  49.                 launcher:pageLayoutPaddingRight="@dimen/apps_customize_pageLayoutPaddingRight"  
  50.                 launcher:widgetCellWidthGap="@dimen/apps_customize_widget_cell_width_gap"  
  51.                 launcher:widgetCellHeightGap="@dimen/apps_customize_widget_cell_height_gap"  
  52.                 launcher:widgetCountX="@integer/apps_customize_widget_cell_count_x"  
  53.                 launcher:widgetCountY="@integer/apps_customize_widget_cell_count_y"  
  54.                 launcher:clingFocusedX="@integer/apps_customize_cling_focused_x"  
  55.                 launcher:clingFocusedY="@integer/apps_customize_cling_focused_y"  
  56.                 launcher:maxGap="@dimen/workspace_max_gap" />  
  57.             <ImageView  
  58.                 android:id="@+id/animation_buffer"  
  59.                 android:layout_width="match_parent"  
  60.                 android:layout_height="match_parent"  
  61.                 android:visibility="gone" />  
  62.   
  63.             <!-- 蓝色翻页指示线 -->  
  64.             <include  
  65.                 android:id="@+id/paged_view_indicator"  
  66.                 layout="@layout/scroll_indicator"  
  67.                 android:layout_width="wrap_content"  
  68.                 android:layout_height="wrap_content"  
  69.                 android:layout_gravity="bottom" />  
  70.         </FrameLayout>  
  71.     </LinearLayout>  
  72.   
  73.     <!-- 第一次进入到菜单界面时弹出的操作介绍界面 -->  
  74.     <include layout="@layout/all_apps_cling"  
  75.         android:id="@+id/all_apps_cling"  
  76.         android:layout_width="match_parent"  
  77.         android:layout_height="match_parent"  
  78.         android:visibility="gone" />  
  79. </com.android.launcher2.AppsCustomizeTabHost>  

     菜单界面视图由自定义视图类AppsCustomizeTabHost描述,该类继承TabHost,在菜单界面视图中,包含了一个LinearLayout布局和一个id为all_apps_cling的视图布局(对应的布局为all_apps_cling):

     -->LinearLayout布局中又包含了两个FrameLayout(对应的id分别为tabs_container、tabcontent)。

         -->id为tabs_container的FrameLayout中包含了菜单界面中"应用程序"和“窗口小部件”这两个子Tab标签的视图布局(FocusOnlyTabWidget)和点击进入“应用商店“的图标(对应布局为market_button)。

         -->id为tabcontent的FrameLayout中包含了用来承载应用程序图标和widget的界面视图布局(AppsCustomizePagedView)和指示翻页操作的蓝色指示线(对应布局为scroll_indicator)。

     -->id为all_apps_cling的视图布局为手机恢复出厂设置(或清空Launcher数据)后第一次进入到菜单界面时弹出的操作介绍界面,如下图的界面:

          

      7). id为hotseat的子视图:该子视图对应的布局为hotseat,hotseat.xml文件的代码如下:

[html] view plaincopy
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <com.android.launcher2.Hotseat  
  3.     xmlns:android="http://schemas.android.com/apk/res/android"  
  4.     xmlns:launcher="http://schemas.android.com/apk/res/com.android.launcher"  
  5.     android:background="@drawable/hotseat_bg_panel"  
  6.     launcher:cellCountX="5"  
  7.     launcher:cellCountY="1">  
  8.     <com.android.launcher2.CellLayout  
  9.         android:id="@+id/layout"  
  10.         android:layout_width="wrap_content"  
  11.         android:layout_height="match_parent"  
  12.         android:layout_gravity="center"  
  13.         android:paddingTop="@dimen/button_bar_height_top_padding"  
  14.         android:paddingBottom="@dimen/button_bar_height_bottom_padding"  
  15.         android:paddingLeft="@dimen/button_bar_width_left_padding"  
  16.         android:paddingRight="@dimen/button_bar_width_right_padding"  
  17.   
  18.         launcher:cellWidth="@dimen/hotseat_cell_width"  
  19.         launcher:cellHeight="@dimen/hotseat_cell_height"  
  20.         launcher:widthGap="@dimen/hotseat_width_gap"  
  21.         launcher:heightGap="@dimen/hotseat_height_gap"  
  22.         launcher:maxGap="@dimen/workspace_max_gap" />  
  23. </com.android.launcher2.Hotseat>  
       hotseat视图布局由自定义视图类Hotseat描述,该类继承自FrameLayout;hotseat视图布局包含一个CellLayout;hotseat视图布局区域就是上文图1中分割线以下的区域,如下图所示:

          

       点击中间的菜单按钮实现进入菜单界面,hotseat中的快捷图标也可以任意拖拽放置(也可以将hotseat中的快捷图标拖拽到Workspace中放置);

      8). id为workspace_cling的子视图:该视图对应的布局文件为workspace_cling.xml。视图布局为手机恢复出厂设置(或清空Launcher数据)后第一次进入到workspace时弹出的操作介绍界面,如下图所示:

                

      9). id为folder_cling的子视图:该视图对应的布局文件为folder_cling.xml;视图布局为手机恢复出厂设置(或清空Launcher数据)后第一次打开文件夹时弹出的操作介绍界面,如下图所示:

          

   


0 0
原创粉丝点击