android Launcher源碼解析01:UI布局詳解一

來源:互聯網
上載者:User

        本系列文章將開始android lancher源碼分析,使用的例子是android 2.3中內建的launcher3源碼。其為:http://download.csdn.net/detail/xianming01/4383598

        本文為第一篇文章,介紹一下lancher的UI布局。

1、布局

      運行該APK,則其執行結果為:

       

      按home鍵以後:

2、布局檔案

       我們來看一下,lancher的布局檔案launcher.xml,其源碼為:

<com.android.launcher3.DragLayer    xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:launcher="http://schemas.android.com/apk/res/com.android.launcher3"    android:id="@+id/drag_layer"    android:layout_width="match_parent"    android:layout_height="match_parent">    <include layout="@layout/all_apps" />    <!-- The workspace contains 3 screens of cells -->    <com.android.launcher3.Workspace        android:id="@+id/workspace"        android:layout_width="match_parent"        android:layout_height="match_parent"        android:scrollbars="horizontal"        android:fadeScrollbars="true"        launcher:defaultScreen="2">        <include android:id="@+id/cell1" layout="@layout/workspace_screen" />        <include android:id="@+id/cell2" layout="@layout/workspace_screen" />        <include android:id="@+id/cell3" layout="@layout/workspace_screen" />        <include android:id="@+id/cell4" layout="@layout/workspace_screen" />        <include android:id="@+id/cell5" layout="@layout/workspace_screen" />    </com.android.launcher3.Workspace>    <com.android.launcher3.ClippedImageView        android:id="@+id/previous_screen"        android:layout_width="93dip"        android:layout_height="@dimen/button_bar_height"        android:layout_gravity="bottom|left"        android:layout_marginLeft="6dip"        android:scaleType="center"        android:src="@drawable/home_arrows_left"                android:onClick="previousScreen"        launcher:ignoreZone="56dip"        android:focusable="true"        android:clickable="true" />    <com.android.launcher3.ClippedImageView        android:id="@+id/next_screen"        android:layout_width="93dip"        android:layout_height="@dimen/button_bar_height"        android:layout_gravity="bottom|right"        android:layout_marginRight="6dip"        android:scaleType="center"        android:src="@drawable/home_arrows_right"                android:onClick="nextScreen"                launcher:ignoreZone="-56dip"                android:focusable="true"        android:clickable="true" />    <com.android.launcher3.DeleteZone        android:id="@+id/delete_zone"        android:layout_width="@dimen/delete_zone_size"        android:layout_height="@dimen/delete_zone_size"        android:paddingLeft="@dimen/delete_zone_padding"        android:layout_marginBottom="@dimen/half_status_bar_height"        android:layout_gravity="right|center_vertical"        android:scaleType="center"        android:src="@drawable/delete_zone_selector"        android:visibility="invisible"        launcher:direction="vertical"        />    <RelativeLayout        android:id="@+id/all_apps_button_cluster"        android:layout_height="fill_parent"        android:layout_width="@dimen/button_bar_height_portrait"        android:layout_gravity="right|center_vertical"        android:layout_marginBottom="@dimen/half_status_bar_height"        >        <com.android.launcher3.HandleView            style="@style/HotseatButton"            android:id="@+id/all_apps_button"            android:layout_centerVertical="true"            android:layout_alignParentRight="true"            android:src="@drawable/all_apps_button"            launcher:direction="vertical"            />        <ImageView            android:id="@+id/hotseat_left"            style="@style/HotseatButton.Left"            android:layout_below="@id/all_apps_button"            android:src="@drawable/hotseat_phone"            android:onClick="launchHotSeat"            />        <ImageView            android:id="@+id/hotseat_right"            style="@style/HotseatButton.Right"            android:layout_above="@id/all_apps_button"            android:src="@drawable/hotseat_browser"            android:onClick="launchHotSeat"            />    </RelativeLayout></com.android.launcher3.DragLayer>

3、布局檔案分析      

  針對其中的各個部分,其圖形為:

  • launcher的第一層次UI 是DragLayer
  • DragLayer 有幾個child,其中最重要的是WorkPlace 和 AllApps2D如下:
  • WorkPlace有五個child,每個是一個CellLayout
每個CellLayout裡面放一些放widget和應用捷徑(BubbleTextView)
  • AllApps2D 展示所有應用列表
參考資料:4 . launcher 的UI布局詳解

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.