天天看點

android 4.0 Launcher

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

android 4.0 Launcher

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

android 4.0 Launcher

<a href="https://yqfile.alicdn.com/img_9bb35c82a54e2dfbdbecb758c1a1d1ca.jpg" target="_blank">點選檢視大圖</a>

整個Launcher.xml布局檔案如下:

&lt;com.android.launcher2.DragLayer 

    xmlns:android="http://schemas.android.com/apk/res/android" 

    xmlns:launcher="http://schemas.android.com/apk/res/com.android.launcher" 

    android:id="@+id/drag_layer" 

    android:layout_width="match_parent" 

    android:layout_height="match_parent"&gt; 

    &lt;!-- Keep these behind the workspace so that they are not visible when 

         we go into AllApps --&gt; 

    &lt;include 

        android:id="@+id/dock_divider" 

        layout="@layout/workspace_divider" 

        android:layout_width="match_parent" 

        android:layout_height="wrap_content" 

        android:layout_marginBottom="@dimen/button_bar_height" 

        android:layout_gravity="bottom"  /&gt; 

        android:id="@+id/paged_view_indicator" 

        layout="@layout/scroll_indicator" 

        android:layout_width="wrap_content" 

        android:layout_gravity="bottom" 

        android:layout_marginBottom="@dimen/button_bar_height"  /&gt; 

    &lt;!-- The workspace contains 5 screens of cells --&gt; 

    &lt;com.android.launcher2.Workspace 

        android:id="@+id/workspace" 

        android:layout_height="match_parent" 

        android:paddingTop="@dimen/qsb_bar_height_inset" 

        android:paddingBottom="@dimen/button_bar_height" 

        launcher:defaultScreen="2" 

        launcher:cellCountX="4" 

        launcher:cellCountY="4" 

        launcher:pageSpacing="@dimen/workspace_page_spacing" 

        launcher:scrollIndicatorPaddingLeft="@dimen/workspace_divider_padding_left" 

        launcher:scrollIndicatorPaddingRight="@dimen/workspace_divider_padding_right"&gt; 

        &lt;include android:id="@+id/cell1" layout="@layout/workspace_screen"  /&gt; 

        &lt;include android:id="@+id/cell2" layout="@layout/workspace_screen"  /&gt; 

        &lt;include android:id="@+id/cell3" layout="@layout/workspace_screen"  /&gt; 

        &lt;include android:id="@+id/cell4" layout="@layout/workspace_screen"  /&gt; 

        &lt;include android:id="@+id/cell5" layout="@layout/workspace_screen"  /&gt; 

    &lt;/com.android.launcher2.Workspace&gt; 

    &lt;include layout="@layout/hotseat" 

        android:id="@+id/hotseat" 

        android:layout_height="@dimen/button_bar_height_plus_padding" 

        android:id="@+id/qsb_bar" 

        layout="@layout/qsb_bar"  /&gt; 

    &lt;include layout="@layout/apps_customize_pane" 

        android:id="@+id/apps_customize_pane" 

        android:visibility="invisible"  /&gt; 

    &lt;include layout="@layout/workspace_cling" 

        android:id="@+id/workspace_cling" 

        android:visibility="gone"  /&gt; 

    &lt;include layout="@layout/folder_cling" 

        android:id="@+id/folder_cling" 

&lt;/com.android.launcher2.DragLayer&gt; 

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

再下面是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和檔案夾。

android 4.0 Launcher

<a href="https://yqfile.alicdn.com/img_b3c4bc901baeca9773c9a3089ec171b4.jpg" target="_blank">點選檢視大圖</a>

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

android 4.0 Launcher

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

android 4.0 Launcher

<a href="https://yqfile.alicdn.com/img_d5220210b64b549413717a351f532c04.jpg" target="_blank">點選檢視大圖</a>

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

android 4.0 Launcher

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

android 4.0 Launcher

緊接着是3個初始化時被隐藏的界面。

apps_customize_pane,點選dock中顯示所有應用程式的按鈕後才會從隐藏狀态轉換為顯示狀态,如下圖所示,顯示了所有應用程式和所有插件的界面。

android 4.0 Launcher

<a href="https://yqfile.alicdn.com/img_f876f806c09f59389d812882658cdba2.jpg" target="_blank">點選檢視大圖</a>

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

android 4.0 Launcher

<a href="https://yqfile.alicdn.com/img_c60b5e04f13d6010379416c68f1ea89b.jpg" target="_blank">點選檢視大圖</a>

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

android 4.0 Launcher

<a href="https://yqfile.alicdn.com/img_43796e193fad1158ff42e06b5c065ba6.jpg" target="_blank">點選檢視大圖</a>

workspace_cling  和 folder_cling 是剛刷完機後,進入桌面時,顯示的使用向導界面,介紹怎麼使用workspace和folder,跳過以後就再也不會出現了,這裡就不截圖了。

上一篇: ios 相關

繼續閱讀