Launcher3源码分析之布局分析

Launcher3中会在Launcher.java中加载主布局launcher.xml

<com.android.launcher3.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">

    <com.android.launcher3.dragndrop.DragLayer
        android:id="@+id/drag_layer"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:clipChildren="false"
        android:clipToPadding="false"
        android:importantForAccessibility="no">

        <!-- The workspace contains 5 screens of cells -->
        <!-- DO NOT CHANGE THE ID -->
        <com.android.launcher3.Workspace
            android:id="@+id/workspace"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_gravity="center"
            android:theme="@style/HomeScreenElementTheme"
            launcher:pageIndicator="@+id/page_indicator" />

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

        <!-- Keep these behind the workspace so that they are not visible when
         we go into AllApps -->
        <com.android.launcher3.pageindicators.WorkspacePageIndicator
            android:id="@+id/page_indicator"
            android:layout_width="match_parent"
            android:layout_height="4dp"
            android:layout_gravity="bottom|center_horizontal"
            android:theme="@style/HomeScreenElementTheme" />

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

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

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

        <!-- DO NOT CHANGE THE ID -->
        <include
            android:id="@+id/hotseat"
            layout="@layout/hotseat"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />
    </com.android.launcher3.dragndrop.DragLayer>

</com.android.launcher3.LauncherRootView>

常规状态下,几个主要的区域如下图所示

Workspace(@+id/workspace)是显示图标和widget的主体;PageIndicator(@+id/page_indicator,代码中是一个具体的对象WorkspcaePageIndicator)是页面指示器,用于指示滑动和表明当前页面;HotSeat(@+id/hoseat)是常驻底部的图标栏;DragLayer是包在这些View的外层的一个ViewGroup,Launcher的拖拽操作需要依赖其内部实现。

这里面有一些常规情况下隐藏起来的重要区域,首先是@+id/overview_panel_container。在Android9.0上,Recent界面不像以前一样进入到SystemUI的新页面,而是与Launcher的内容结合起来。这个ViewGroup就是显示Recent内容的控件。

然后还有@+id/drop_target_bar,当拖动图标或widget的内容时,出现在Launcher上方用于执行特定操作的控件。

还要注意的是,在Android9.0上已经没有overview_panel了,长按桌面空白页面出现的是

最后是@+id/apps_view,这就是应用抽屉了,容纳了所有应用图标。

桌面上的每一页是一个CellLayout(也是一个自定义的ViewGroup),当有多页时,就一个个横向排布在Workspace中,当触摸滑动桌面时,通过scrollTo来改变workspace内部子View的位置,就可以使用户看到不同页的内容。

对于图标的排布,CellLayout还不是真正容纳图标和Widget的ViewGroup。每一个CellLayout会包含一个ShortAndWidgetContainer,这个才是真正容纳图标和Widget的ViewGroup。

以上就是Launcher3的布局的大概信息。

参考文章:

Android 9.0 Launcher源码分析(三)——Launcher的布局与多设备适配

 

 

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值