自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

【專家專欄】Android 4.0 Launcher源碼分析系列(一)

原創(chuàng)
移動開發(fā) Android
著名手機廠商Android開發(fā)工程師、最牛網(wǎng)站長傻蛋曾為51CTO撰稿《Android 4.0的圖形硬件加速及繪制技巧》受到讀者的廣泛歡迎。傻蛋同學將在新的一年里在51CTO開設(shè)專家專欄,本文為傻蛋正在研究的一個方向,與網(wǎng)友共同探討Android 4.0原生的桌面程序——Launcher。

從今天起傻蛋打算做一個系列文章,對最新的Android 4.0 系統(tǒng)中的Launcher,也就是Android 4.0原生的桌面程序,進行一個深入淺出的分析,從而引領(lǐng)Android系統(tǒng)的編程愛好者對 Launcher的設(shè)計思想,實現(xiàn)方式來做一個研究,從而能夠通過這個實例最掌握到目前世界領(lǐng)先的設(shè)計方法,同時在程序中加入我們的一些新的實現(xiàn)。眾所周知,對一些優(yōu)秀源代碼的分析,是提高編程水平的一條便捷的方式,希望本系列文章能夠給大家?guī)硪欢ǖ膯l(fā),同時歡迎大家和作者一起討論,作者的微博是:http://weibo.com/zuiniuwang/

先從整體上對Launcher布局作一個分析,讓我們通過查看Launcher.xml 和使用hierarchyviewer布局查看工具兩者結(jié)合的方法來對Launcher的整體結(jié)構(gòu)有個了解。通過hierarchyviewer來對整個桌面做個截圖,如下:

通過hierarchyviewer來對整個桌面做個截圖

放大后如下所示: 可以看到整個桌面包含的元素,最上面是Google的搜索框,下面是一個始終插件,然后是圖標,再有就是一個分隔線,最后是dock。請注意,桌面程序其實并不包含桌面壁紙,桌面壁紙其實是由 WallpaperManagerService來提供,整個桌面其實是疊加在整個桌面壁紙上的另外一個層。

放大后所示

點擊查看大圖

整個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.  
  5.     android:id="@+id/drag_layer" 
  6.     android:layout_width="match_parent" 
  7.     android:layout_height="match_parent"> 
  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.         android:layout_width="match_parent" 
  15.         android:layout_height="wrap_content" 
  16.         android:layout_marginBottom="@dimen/button_bar_height" 
  17.         android:layout_gravity="bottom"  /> 
  18.     <include 
  19.         android:id="@+id/paged_view_indicator" 
  20.         layout="@layout/scroll_indicator" 
  21.         android:layout_width="wrap_content" 
  22.         android:layout_height="wrap_content" 
  23.         android:layout_gravity="bottom" 
  24.         android:layout_marginBottom="@dimen/button_bar_height"  /> 
  25.  
  26.     <!-- The workspace contains 5 screens of cells --> 
  27.     <com.android.launcher2.Workspace 
  28.         android:id="@+id/workspace" 
  29.         android:layout_width="match_parent" 
  30.         android:layout_height="match_parent" 
  31.         android:paddingTop="@dimen/qsb_bar_height_inset" 
  32.         android:paddingBottom="@dimen/button_bar_height" 
  33.         launcher:defaultScreen="2" 
  34.         launcher:cellCountX="4" 
  35.         launcher:cellCountY="4" 
  36.         launcher:pageSpacing="@dimen/workspace_page_spacing" 
  37.         launcher:scrollIndicatorPaddingLeft="@dimen/workspace_divider_padding_left" 
  38.         launcher:scrollIndicatorPaddingRight="@dimen/workspace_divider_padding_right"> 
  39.  
  40.         <include android:id="@+id/cell1" layout="@layout/workspace_screen"  /> 
  41.         <include android:id="@+id/cell2" layout="@layout/workspace_screen"  /> 
  42.         <include android:id="@+id/cell3" layout="@layout/workspace_screen"  /> 
  43.         <include android:id="@+id/cell4" layout="@layout/workspace_screen"  /> 
  44.         <include android:id="@+id/cell5" layout="@layout/workspace_screen"  /> 
  45.     </com.android.launcher2.Workspace> 
  46.  
  47.     <include layout="@layout/hotseat" 
  48.         android:id="@+id/hotseat" 
  49.         android:layout_width="match_parent" 
  50.         android:layout_height="@dimen/button_bar_height_plus_padding" 
  51.         android:layout_gravity="bottom"  /> 
  52.  
  53.     <include 
  54.         android:id="@+id/qsb_bar" 
  55.         layout="@layout/qsb_bar"  /> 
  56.  
  57.     <include layout="@layout/apps_customize_pane" 
  58.         android:id="@+id/apps_customize_pane" 
  59.         android:layout_width="match_parent" 
  60.         android:layout_height="match_parent" 
  61.         android:visibility="invisible"  /> 
  62.  
  63.     <include layout="@layout/workspace_cling" 
  64.         android:id="@+id/workspace_cling" 
  65.         android:layout_width="match_parent" 
  66.         android:layout_height="match_parent" 
  67.         android:visibility="gone"  /> 
  68.  
  69.     <include layout="@layout/folder_cling" 
  70.         android:id="@+id/folder_cling" 
  71.         android:layout_width="match_parent" 
  72.         android:layout_height="match_parent" 
  73.         android:visibility="gone"  /> 
  74. </com.android.launcher2.DragLayer> 

Launcher整個布局的根是DragLayer,DragLayer繼承了FrameLayout,所以DragLayer本身可以看作是一個FrameLayout。下面是 dock_divider,它通過include關(guān)鍵字包含了另外一個布局文件workspace_divider.xml ,而這個workspace_divider.xml包含了一ImageView,其實dock_divider就是dock區(qū)域上面的那條直線。

再下面是paged_view_indicator,同樣它包含了scroll_indicator.xml,其中包含了一個ImageView,顯示的是一個.9的png文件。實際上就是當Launcher滾動翻頁的時候,那個淡藍色的頁面指示條。

然后桌面的核心容器WorkSpace,如下圖所示,當然你看到的只是Workspace的一部分,其實是一個workspace_screen,通過 Launcher.xml可以看到,整個workspace由5個workspace_screen組成,每個workspace_screen其實就是對應(yīng)桌面一頁。而每個workspace_screen包含了一個CellLayout,這是一個自定義控件,繼承自ViewGroup,所以它算是一個用來布局的控件,在這里主要用來承載我們每頁的桌面圖標、widget和文件夾。

桌面的核心容器WorkSpace

點擊查看大圖

 通過查看如下的布局結(jié)構(gòu)(由于圖太大只截取了一部分)可以看到,Workspace包含了序號從0到4的5個CellLayout。

查看布局結(jié)構(gòu)

接下來是一個Hotseat,其實就是這塊dock區(qū)域了。如圖所示:

dock區(qū)域

點擊查看大圖

 從如下的布局圖我們可以看到,這個Hotseat其實還是包含了一個CellLayout,用來承載4個圖標和中間啟動所有程序的按鈕。

用來承載4個圖標和中間啟動所有程序的按鈕

 再下來就是那個qsb_bar,就是屏幕最頂端的Google搜索框。這個搜索框是獨立于圖標界面的,所以當我們對桌面進行翻頁的時候,這個搜索框會巍然不動滴固定在最頂端,如下所示:

最頂端的Google搜索框

緊接著是3個初始化時被隱藏的界面。

apps_customize_pane,點擊dock中顯示所有應(yīng)用程序的按鈕后才會從隱藏狀態(tài)轉(zhuǎn)換為顯示狀態(tài),如下圖所示,顯示了所有應(yīng)用程序和所有插件的界面。

所有應(yīng)用程序和所有插件的界面

點擊查看大圖

 通過查看apps_customize_pane.xml ,我們可以看到apps_customize_pane主要由兩部分組成:tabs_container 和tabcontent。tabs部分,用來讓我們選擇是添加應(yīng)用程序還是widget,如下圖所示:

用來讓我們選擇是添加應(yīng)用程序還是widget

點擊查看大圖

tabcontent,選擇了相應(yīng)的tab之后,下面的部分就會相應(yīng)的顯示應(yīng)用程序或是widget了,如下圖所示:

面的部分就會相應(yīng)的顯示應(yīng)用程序或是widget

點擊查看大圖

workspace_cling  和 folder_cling 是剛刷完機后,進入桌面時,顯示的使用向?qū)Ы缑?,介紹怎么使用workspace和folder,跳過以后就再也不會出現(xiàn)了,這里就不截圖了。

 【51CTO.com獨家特稿,非經(jīng)授權(quán)謝絕轉(zhuǎn)載,合作媒體轉(zhuǎn)載請注明原文作者及出處!】

責任編輯:佚名 來源: 51CTO.com
相關(guān)推薦

2012-02-13 12:47:41

Android 4.0Launcher源碼分析

2012-02-02 15:56:48

Android 4.0Launcher源碼分析

2012-07-23 13:22:42

Intent Filt安全Android

2012-06-05 10:09:45

AndroidManiAndroidMani

2011-08-01 13:35:08

Android安全框架權(quán)限

2012-09-27 09:25:50

2012-07-16 10:21:48

Android進程線程

2012-07-04 09:07:40

2011-08-12 09:06:48

Android系統(tǒng)應(yīng)用程序

2011-08-29 13:52:15

李洋Android應(yīng)用

2011-08-22 08:53:17

Android啟動過程李洋

2011-09-06 13:56:43

李洋iOS安全機制

2010-08-01 16:11:53

Android

2010-05-28 17:30:58

SVN分支

2011-09-15 08:58:41

Android短信丟失技術(shù)原因

2012-04-04 11:41:31

三星

2010-10-26 11:04:48

OWASP專家采訪方興

2010-10-26 10:56:00

OWASP專家采訪夏鵬

2010-11-08 16:58:36

OWASP專家采訪魏彩霞

2012-02-15 10:05:02

Linux命令行
點贊
收藏

51CTO技術(shù)棧公眾號