Android Launcher源码研究(一) 基本结构

Launcher 是 Android手机开启后第一个运行的 应用程序,也叫Home,或者叫做手机桌面。
本文介绍的是4.1源码的launcher2 app. Android41\packages\apps\Launcher2




首先找到主Activity,打开AndroidManifest.xml  入口是  com.android.launcher2.Launcher 这个类
Launcher 主界面包含 wallpaper墙纸,work_screen屏幕, 最底部的hotseat, 以及all apps.

onCreate方法里面 主要初始化一些对象,包括拖拽对象,hotSeat,  墙纸大小设置,
打开主布局文件launcher.xml
外层是一个Framelayout叠层 com.android.launcher2.DragLayer
com.android.launcher2.Workspace.java 为主要Home Screen
手机里面包含了多个屏的滑动,一共有5个
    <com.android.launcher2.Workspace
        android:id="@+id/workspace"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:paddingLeft="@dimen/workspace_left_padding"
        android:paddingRight="@dimen/workspace_right_padding"
        android:paddingTop="@dimen/workspace_top_padding"
        android:paddingBottom="@dimen/workspace_bottom_padding"
        launcher:defaultScreen="2"
        launcher:cellCountX="@integer/cell_count_x"
        launcher:cellCountY="@integer/cell_count_y"
        launcher:pageSpacing="@dimen/workspace_page_spacing"
        launcher:scrollIndicatorPaddingLeft="@dimen/qsb_bar_height"
        launcher:scrollIndicatorPaddingRight="@dimen/button_bar_height">

        <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.launcher2.Workspace>


每一个屏叫做 com.android.launcher2.CellLayout.java
<com.android.launcher2.CellLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:launcher="http://schemas.android.com/apk/res/com.android.launcher"

    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:paddingLeft="@dimen/cell_layout_left_padding"
    android:paddingRight="@dimen/cell_layout_right_padding"
    android:paddingTop="@dimen/cell_layout_top_padding"
    android:paddingBottom="@dimen/cell_layout_bottom_padding"
    android:hapticFeedbackEnabled="false"

    launcher:cellWidth="@dimen/workspace_cell_width"
    launcher:cellHeight="@dimen/workspace_cell_height"
    launcher:widthGap="@dimen/workspace_width_gap"
    launcher:heightGap="@dimen/workspace_height_gap"
    launcher:maxGap="@dimen/workspace_max_gap" />


Workspace.java 是继承ViewGroup
CellLayout 也是继承ViewGroup

Workspace.java 对象在Launcher里面做了一些初始化。
首先在setupViews方法里面 获取了对象引用。还包含了shortcut添加与删除操作。

在Workspace.java中onTouchEvent方法中,监听了屏幕的滑动操作,比如长按,拖动app图标。
拖动用DragController.java类,处理拖动计算坐标。




暂时说到这,如有问题,请指出谢谢。

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值