Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1251264
  • 博文数量: 247
  • 博客积分: 5587
  • 博客等级: 大校
  • 技术积分: 2060
  • 用 户 组: 普通用户
  • 注册时间: 2010-02-24 13:27
文章分类
文章存档

2012年(101)

2011年(44)

2010年(102)

分类: 嵌入式

2012-03-22 16:53:13

本文是在参考: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分析一下,官方代码是:

 

 

 

    xmlns:android=""

    xmlns:launcher=""

 

    android:id="@+id/drag_layer"

    android:layout_width="match_parent"

    android:layout_height="match_parent">

 

    

 

    

    

        android:id="@+id/workspace"

        android:layout_width="match_parent"

        android:layout_height="match_parent"

        android:scrollbars="horizontal"

        android:fadeScrollbars="true"

        launcher:defaultScreen="2">

 

        

        

        

        

        

 

    

 

    

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

 

    

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

 

    

        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"

        />

 

    

        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"

        >

 

        

            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"

            />

 

        

            android:id="@+id/hotseat_left"

            style="@style/HotseatButton.Left"

            android:layout_below="@id/all_apps_button"


            android:src="@drawable/hotseat_setting"


            android:onClick="launchHotSeat"

            /> 

 

        

            android:id="@+id/hotseat_right"

            style="@style/HotseatButton.Right"

            android:layout_above="@id/all_apps_button"

 

            android:src="@drawable/hotseat_browser"

 

            android:onClick="launchHotSeat"

            /> 

 

    


 

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

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

 

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

 

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

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

 

源代码;

 

 

    xmlns:android=""

    xmlns: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的基本特性,后续还会加深研究。

阅读(5660) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~