日韩无码专区无码一级三级片|91人人爱网站中日韩无码电影|厨房大战丰满熟妇|AV高清无码在线免费观看|另类AV日韩少妇熟女|中文日本大黄一级黄色片|色情在线视频免费|亚洲成人特黄a片|黄片wwwav色图欧美|欧亚乱色一区二区三区

RELATEED CONSULTING
相關咨詢
選擇下列產(chǎn)品馬上在線溝通
服務時間:8:30-17:00
你可能遇到了下面的問題
關閉右側工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
【專家專欄】Android4.0Launcher源碼分析系列(一)

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

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

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

點擊查看大圖

整個Launcher.xml布局文件如下:

 
 
 
 
  1.     xmlns:android="http://schemas.android.com/apk/res/android" 
  2.     xmlns:launcher="http://schemas.android.com/apk/res/com.android.launcher" 
  3.  
  4.     android:id="@+id/drag_layer" 
  5.     android:layout_width="match_parent" 
  6.     android:layout_height="match_parent"> 
  7.  
  8.      
  9.     
  10.         android:id="@+id/dock_divider" 
  11.         layout="@layout/workspace_divider" 
  12.         android:layout_width="match_parent" 
  13.         android:layout_height="wrap_content" 
  14.         android:layout_marginBottom="@dimen/button_bar_height" 
  15.         android:layout_gravity="bottom"  /> 
  16.     
  17.         android:id="@+id/paged_view_indicator" 
  18.         layout="@layout/scroll_indicator" 
  19.         android:layout_width="wrap_content" 
  20.         android:layout_height="wrap_content" 
  21.         android:layout_gravity="bottom" 
  22.         android:layout_marginBottom="@dimen/button_bar_height"  /> 
  23.  
  24.      
  25.     
  26.         android:id="@+id/workspace" 
  27.         android:layout_width="match_parent" 
  28.         android:layout_height="match_parent" 
  29.         android:paddingTop="@dimen/qsb_bar_height_inset" 
  30.         android:paddingBottom="@dimen/button_bar_height" 
  31.         launcher:defaultScreen="2" 
  32.         launcher:cellCountX="4" 
  33.         launcher:cellCountY="4" 
  34.         launcher:pageSpacing="@dimen/workspace_page_spacing" 
  35.         launcher:scrollIndicatorPaddingLeft="@dimen/workspace_divider_padding_left" 
  36.         launcher:scrollIndicatorPaddingRight="@dimen/workspace_divider_padding_right"> 
  37.  
  38.          
  39.          
  40.          
  41.          
  42.          
  43.      
  44.  
  45.     
  46.         android:id="@+id/hotseat" 
  47.         android:layout_width="match_parent" 
  48.         android:layout_height="@dimen/button_bar_height_plus_padding" 
  49.         android:layout_gravity="bottom"  /> 
  50.  
  51.     
  52.         android:id="@+id/qsb_bar" 
  53.         layout="@layout/qsb_bar"  /> 
  54.  
  55.     
  56.         android:id="@+id/apps_customize_pane" 
  57.         android:layout_width="match_parent" 
  58.         android:layout_height="match_parent" 
  59.         android:visibility="invisible"  /> 
  60.  
  61.     
  62.         android:id="@+id/workspace_cling" 
  63.         android:layout_width="match_parent" 
  64.         android:layout_height="match_parent" 
  65.         android:visibility="gone"  /> 
  66.  
  67.     
  68.         android:id="@+id/folder_cling" 
  69.         android:layout_width="match_parent" 
  70.         android:layout_height="match_parent" 
  71.         android:visibility="gone"  /> 
  72.  

Launcher整個布局的根是DragLayer,DragLayer繼承了FrameLayout,所以DragLayer本身可以看作是一個FrameLayout。下面是 dock_divider,它通過include關鍵字包含了另外一個布局文件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其實就是對應桌面一頁。而每個workspace_screen包含了一個CellLayout,這是一個自定義控件,繼承自ViewGroup,所以它算是一個用來布局的控件,在這里主要用來承載我們每頁的桌面圖標、widget和文件夾。

點擊查看大圖

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

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

點擊查看大圖

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

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

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

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

點擊查看大圖

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

點擊查看大圖

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

點擊查看大圖

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

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


當前文章:【專家專欄】Android4.0Launcher源碼分析系列(一)
鏈接地址:http://www.5511xx.com/article/djgihjd.html