1. 什么是android的Launcher ?

答: 把它理解成Android的“桌面启动器”,就是我们 启动手机或者平板电脑后显示在我们眼前的这个界面,相当于Windows的桌面

另外,好像是从android2.1版本开始launcher的版本变成了launcher2。


2. Launcher和系统层是否有关联?

答:没有关联,launcher就相当于一个应用程序一样。当你修改launcher时,无需全编译,只需要编译这个launcher即可,这里称之为小编译,编译后一起打包就能升级启动

注:我这里把关联理解为是否和底层的C库或者内核关联。

3. Launcher包含哪些?

答: 从界面上来看,launcher2的界面构成如图1所示:

<为知更新>android 的 Launcher 分析_第1张图片

图1 Android2.3.4 的Launcher2 界面布局示意图

Launcher包含了workspace壁纸、左右下角的点(单击这个点可以切换屏幕)、右边的DeleteZone 和HandleView。

那么什么是workspace呢? 当你左右滑动屏幕时,每个屏幕就相当于一个workspace,一般来说我们可以自定义屏幕的数目平常我们见到的都是5个

如图1所示,我们可以看到有workspace、workspace中包含的cell(就是那些小方格)。壁纸、DeleteZone 和HandleView我没有画出来,这个大家可以打开android手机一看就知道了。

注意:状态栏statusbar不属于Launcher,状态栏和系统层有关,关于状态栏的修改请点击这里

4. Launcher的源代码在那个目录下?包含哪些文件?

答:主要包含几个java文件和xml文件,当然了,还有图片文件

因为Launcher好比一个应用程序一样,所以他的目录主要就在packages包下面。

java文件:/packages/apps/Launcher2/src/com/android/launcher2/

xml文件和图片等文件:/packages/apps/Launcher2/res/

关于java文件的含义,请参看这里

----------------------------------

关于布局文件请看下面的分析。


5. 核心的布局文件有哪些?

答:总布局文件分别在:

横屏: packages/apps/Launcher2/res/layout-land/launcher.xml

竖屏: packages/apps/Launcher2/res/layout-port/launcher.xml

就用横屏的launcher.xml分析一下,官方代码是:

<?xml version="1.0" encoding="utf-8"?>

<!-- Copyright (C) 2007 The Android Open Source Project

Licensed under the Apache License, Version 2.0 (the "License");

you may not use this file except in compliance with the License.

You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software

distributed under the License is distributed on an "AS IS" BASIS,

WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

See the License for the specific language governing permissions and

limitations under the License.

-->

<com.android.launcher2.DragLayer

xmlns:android="http://schemas.android.com/apk/res/android"

xmlns:launcher="http://schemas.android.com/apk/res/com.android.launcher"

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

<com.android.launcher2.ClippedImageView

android:id="@+id/previous_screen"

android:layout_width="70dip"

android:layout_height="@dimen/button_bar_height"

android:layout_gravity="bottom|center_horizontal"

android:layout_marginBottom="-5dip"

android:scaleType="center"

android:src="@drawable/home_arrows_left"

launcher:ignoreZone="56dip"

android:focusable="true"

android:clickable="true" />

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

launcher:ignoreZone="-56dip"

android:focusable="true"

android:clickable="true" />

<com.android.launcher2.DeleteZone

android:id="@+id/delete_zone"

android:layout_width="@dimen/delete_zone_width"

android:layout_height="@dimen/delete_zone_height"

android:layout_gravity="bottom|center_horizontal"

android:scaleType="center"

android:src="@drawable/delete_zone_selector"

android:visibility="invisible"

launcher:direction="horizontal"

/>

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

android:id="@+id/all_apps_button"

android:layout_centerVertical="true"

android:layout_alignParentRight="true"

style="@style/HotseatButton"

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_setting"


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


从这个文件可以很容易看出,包含了workspace,handleview,DeleteZone等。

紫红色背景区域代码正好是5个屏幕的布局,他们都引用了同一个布局文件。

我们可以把右边的handleview和DeleteZone删除掉,只要把蓝色代码区域注释掉,然后把关联的java文件launcher.java文件中有关的部分代码注释掉即可。

6. 能否增加或者减少cell的数量?

答:可以。主要在/packages/res/Launcher2/res/workspase_screen.xml中修改。

源代码;

<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="match_parent"

android:layout_height="match_parent"

android:hapticFeedbackEnabled="false"

launcher:cellWidth="@dimen/workspace_cell_width"

launcher:cellHeight="@dimen/workspace_cell_height"

launcher:longAxisStartPadding="60dip"

launcher:longAxisEndPadding="60dip"

launcher:shortAxisStartPadding="0dip"

launcher:shortAxisEndPadding="45dip"

launcher:shortAxisCells="4"

launcher:longAxisCells="7" />

1) 看绿色区域代码,shortAxisCells表示宽度上cell个数,longAxisCells表示长度上cell得个数。可以根据实际修改这个数字,当然了,如果数字越大,cell就越多,最后很有可能导致屏幕显示不出来,所以个人觉得最好设置小一点。

2) 看黄色区域代码,launcher:cellWidth表示cell的宽度,launcher:cellHeight表示cell的高度。

3) 看紫红色区域代码,具体代码含义请看图1所示,其实一眼就能看得出,这四个变量分别代表workspace与屏幕左右上下的内部距离。

以上数字可以根据实际情况修改。

以上内容比较简单,只是大概介绍了launcher的基本特性,后续还会加深研究。
















更多相关文章

  1. android 代码优化:关闭输出日志
  2. 使用Android内置的Pull解析器解析XML文件
  3. android moudle 资源文件重命名
  4. CrossWalk - android 动态加载so库文件实践
  5. [读书笔记]布局的屏幕适配常用方法

随机推荐

  1. android Activity 设置大小
  2. android Fragment FragmentActivity 选项
  3. android发送通知
  4. Android鍏ラ棬绡囦竴锛欰ndroid Activity
  5. Android和Java ME的区别与联系
  6. Android一些常用的依赖
  7. Android Intent应用,打开网页,安装程序,打电
  8. android中给图片打水印
  9. Android 源码 图形系统之硬件渲染器绘制
  10. 碎片概述(Fragments Overview)----(1)