Android 4.0 Launcher2源碼分析——主布局檔案

來源:互聯網
上載者:User

標籤:drag   nta   target   技術   value   imageview   rtc   --   div   

本文來自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.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.   
  8.     <!-- Keep these behind the workspace so that they are not visible when  
  9.          we go into AllApps -->  
  10.     <include  
  11.         android:id="@+id/dock_divider"  
  12.     layout="@layout/workspace_divider"  
  13.         ...  
  14.      />  
  15.   
  16.     <!-- 分頁指標 -->  
  17.     <include  
  18.         android:id="@+id/paged_view_indicator"  
  19.         layout="@layout/scroll_indicator"  
  20.         ...  
  21.      />  
  22.   
  23.     <!-- The workspace contains 5 screens of cells -->  
  24.     <com.android.launcher2.Workspace  
  25.         android:id="@+id/workspace"  
  26.         ...  
  27.         >  
  28.   
  29.         <!-- 五個分屏,預設顯示cell3 -->  
  30.         <include android:id="@+id/cell1" layout="@layout/workspace_screen" />  
  31.         <include android:id="@+id/cell2" layout="@layout/workspace_screen" />  
  32.         <include android:id="@+id/cell3" layout="@layout/workspace_screen" />  
  33.         <include android:id="@+id/cell4" layout="@layout/workspace_screen" />  
  34.         <include android:id="@+id/cell5" layout="@layout/workspace_screen" />  
  35.     </com.android.launcher2.Workspace>  
  36.   
  37.     <!-- 搜尋方塊/刪除框 -->  
  38.     <include  
  39.         android:id="@+id/qsb_bar"  
  40.         layout="@layout/qsb_bar" />  
  41.   
  42.     <!-- 顯示具體全部應用的介面,包括APPS、WIGHETS的tab標籤,以及顯示ALL APP的頁面和現實APP WIGHETS的頁面 -->  
  43.     <include layout="@layout/apps_customize_pane"  
  44.         android:id="@+id/apps_customize_pane"  
  45.         ..  
  46.     />  
  47.   
  48.     <!-- WorkSpace最下面的五個快捷位置 -->  
  49.     <include layout="@layout/hotseat"  
  50.         android:id="@+id/hotseat"  
  51.         ..  
  52.      />  
  53.   
  54.     <!-- 剛啟動的時候顯示的指導頁 -->  
  55.     <include layout="@layout/workspace_cling"  
  56.         android:id="@+id/workspace_cling"  
  57.         ...  
  58.     />  
  59.   
  60.     <!-- 是第一次進入全部應用之後顯示的指導頁 -->  
  61.     <include layout="@layout/folder_cling"  
  62.         android:id="@+id/folder_cling"  
  63.         ...  
  64.     />  
  65. </com.android.launcher2.DragLayer>  

接著我們來一一認識每一個View控制項。

1、最外層的DragLayer,是一個繼承自FramLayout的View控制項,顯示的就是整個案頭根容器。案頭的所有控制項都是位於DragLayer中。

2、id/dock_divider,使用了布局workspace_divider,其實就是一個ImageView。是Workspace與Hotseat之間的分割線。

3、id/paged_view_indicator,使用了布局scroll_indicator,顯示效果是在id/dock_divider上顯示一條淡藍色的橫線,來指示當分屏所處的位置

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

5、id/cell1..cell5 ,分別代表五個分屏

6、id/qsb_bar 搜尋方塊/刪除框,根據需要進行切換

        

7、id/apps_customize_pane,效果如下

8、id/hotseat 即主畫面下方的五個快捷位置

9、id/workspace_cling當第一次運行Launcher2時,會顯示的用於指導的動畫,以後不再顯示


10、id/folder_cling,第一次使用Folder時,展示給使用者的指導畫面。


這樣,我們已經可以使每個UI介面及組件都對號入座,這會使接下來分析的時候更加清晰。

Android 4.0 Launcher2源碼分析——主布局檔案(轉)

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.