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类,处理拖动计算坐标。



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

更多相关文章

  1. Android中通过网络获取json数据来播放视频
  2. Android之——图片的内存优化
  3. android学习笔记23:幻灯片
  4. android_定义多个Activity及跳转
  5. Android(安卓)ViewPager 实现多个页面切换滑动
  6. Android(安卓)NestedScrolling嵌套滑动机制
  7. 关于异步加载、缓存图片、软引用等
  8. SQLite数据库相关(三) SQLiteOpenHelper类
  9. Android(安卓)ListView 自定义背景滚动变黑问题

随机推荐

  1. Android 高管谈 Lollipop:为何它是 Androi
  2. Android(安卓)NDK 开发 —— 从 Assets
  3. android 怎样做SDK
  4. Android线程学习
  5. Android(安卓)编程下的自定义 xmlns
  6. android provision
  7. RelativeLayout_相对布局 属性的描述
  8. android intent
  9. Android 读写Excel文件
  10. 图解Android - System Service 概论 和 A