Android 源码解析之原生 Launcher3 _UI结构篇

版权声明:本文为博主 Jon.Lo 的原创文章,未经博主授权允许,不得擅自转载,违者将追究相关法律责任。 https://blog.csdn.net/MLQ8087/article/details/81199846

Android 源码解析之原生 Launcher3 _UI 结构篇

一、Launcher简介

    Launcher 是Android 系统 开机完成后,第一个启动的系统级应用,用来展示系统种所预装或安装的应用的快捷方式、小部件的列表。Launcher作为开机后第一个展示给用户的应用程序,其设计的好坏影响到用户的体验,甚至影响用户购机的判断。所以很多品牌厂商都会不遗余力的对Launcher进行深度定制,如小米的MIUI、华为的EMUI等。Android 默认的 Launcher没有过多的定制,更加简洁,受到源生党的追捧,Google的Nexus系列手机基本都是用的源生Launcher,目前Android源生的Launcher版本是Launcher3,后面的相关内容也都是已 Launcher3为基础。

    本篇,我们先来了解 Launcher3 的 UI 界面的 布局层级 和 结构框架;


二、UI 布局层级 分析

从 Google 原生 launcher 的 UI 布局显示的层级来看,Launcher 共分 两层 来显示,分别各为一个 Acitivity:

第一层:就是开机启动后,我看到的第一个界面,也是用户点按 Home键后显示的主页面,我们俗称 “快捷桌面”

第二层:是用来展示系统中安装,且允许在列表中显示的所有的 Apps Widgets 的页面,这是我们常说的 “抽屉页”

这与我们平日里常用安卓手机的 launcher 首页不同,国内几乎所有的手机厂商,都会对 launcher 进行个性化的定制, 因此我们看到都只有一层布局结构,就是 “快捷桌面”

1. 第一层 布局 :LauncherRootView

先来看看 Launcher.java的主布局文件 —— launcher.xml :

<com.android.launcherWT.LauncherRootView
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:launcher="http://schemas.android.com/apk/res-auto"
    android:id="@+id/launcher"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true">

    <!-- JonLo : 20180730 add -->
 <com.android.launcherWT.DragLayer
                android:id="@+id/drag_layer"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_marginTop="0dp">

                <!--<com.android.launcherWT.FocusIndicatorView
                    android:id="@+id/focus_indicator"
                    android:layout_width="52dp"
                    android:layout_height="52dp" />
-->
                <!-- The workspace contains 5 screens of cells -->
                <!-- DO NOT CHANGE THE ID -->
                <com.android.launcherWT.Workspace
                    android:id="@+id/workspace"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_marginTop="0dp"
                    launcher:defaultScreen="@integer/config_workspaceDefaultScreen"
                    launcher:pageIndicator="@id/page_indicator" />

                <!-- DO NOT CHANGE THE ID -->
                <include
                    android:id="@+id/hotseat"
                    layout="@layout/hotseat"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_gravity="right" />

                <include
                    android:id="@+id/search_drop_target_bar"
                    layout="@layout/search_drop_target_bar" />

                <include
                    android:id="@+id/overview_panel"
                    layout="@layout/overview_panel"
                    android:visibility="gone" />

                <!-- Keep these behind the workspace so that they are not visible when
                     we go into AllApps -->
                <include
                    android:id="@+id/page_indicator"
                    layout="@layout/page_indicator"
                    android:layout_width="wrap_content"
                    android:layout_height="5dp"
                    android:layout_gravity="center_horizontal" />

                <include
                    android:id="@+id/widgets_view"
                    layout="@layout/widgets_view"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:visibility="invisible" />

                <include
                    android:id="@+id/apps_view"
                    layout="@layout/all_apps"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:visibility="invisible" />
     </com.android.launcherWT.DragLayer>

    <ViewStub
                android:id="@+id/launcher_overlay_stub"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:inflatedId="@+id/launcher_overlay"
                android:layout="@layout/launcher_
  

</com.android.launcherWT.LauncherRootView>

 LauncherRootView 是 launcher.xml 布局的最外层父布局,它继承自一个系统自定义的 FrameLayout —— InsettableFrameLayout:
public class LauncherRootView extends InsettableFrameLayout {
    public LauncherRootView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    @Override
    protected boolean fitSystemWindows(Rect insets) {
        setInsets(insets);
        return true; // I'll take it from here
    }
}

猜你喜欢

转载自blog.csdn.net/MLQ8087/article/details/81199846