本文是在参考:http://blog.csdn.net/fzh0803/article/details/6279995
文章之后,结合自己修改launcher 时的经历而总结的,如有疑问之处还请指出。
不管如何,得先谢谢上面引用的这个帖子。下文是在Android2.2、2.3的基础上得来的
本文将从以下几个方面来分析。
1. 什么android的Launcher ?
答: 从字面意思来看就是“发射台、启动台、启动物体”的意思,我个人把它理解成Android的“桌面启动器”,就是我们启动手机或者平板电脑后显示在我们眼前的这个界面,相当于Windows的桌面。
另外,好像是从android2.1版本开始launcher的版本变成了launcher2。
2. Launcher和系统层是否有关联?
答:没有关联,launcher就相当于一个应用程序一样。当你修改launcher时,无需全编译,只需要编译这个launcher即可,这里称之为小编译,编译后一起打包就能升级启动。注:我这里把关联理解为是否和底层的C库或者内核关联。
3. Launcher包含哪些?
答: 从界面上来看,launcher2的界面构成如图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的基本特性,后续还会加深研究。
分享到:
相关推荐
Android Launcher 分析
作者:华清远见3G学院。Android Launcher分析--华清远见android培训课件教程。
安卓Android源码——安卓Android Launcher 桌面分页滑动代码.rar
基于原生launcher做定制,做了3个项目了,这里有些经验与大家分享一下,顺便混点分。里边的大部分内容是通用的具有参考价值,小部分内容是我所涉及的项目特定的。
android2.3 launcher分析
android2.3 launcher分析三
android的launcher是一款非常强大的系统应用,值得去好好的研究一番,这里对 Launcher2文件夾功能作详细的分析介绍。
android源码的Launcher详细解析,分析Launcher的运行机制
Android-launcher源码全面分析 一 Launcher默认界面配置(default workspace) 2 1 界面默认配置文件 2 2 LauncherProvider java的loadFavorites分析 3 二 Icon修改 界面布局调整 壁纸设置 5 1 图标大小和标题大小 5...
对Android launcher比较详细的分析
android2.3 launcher分析二
android 4.0 launcher分析
更改官方的Launcher3使得可以在Android Studio编译 原始地址,从5892520提交开始 最小sdk版本为16 Android 5.0 版本及以上可能会出现因为相同权限声明而不能安装的问题 如果你想要可以在Eclipse编译的版本,可以看...
android的launcher分析--详细
android2.3 launcher分析一
Android_launcher的源码详细分析.pdf
android launcher 源码分析,不错的源码资料,分享给大家
android的launcher分析.pdf