2011.06.09——— android 1.6 launcher研究之修改worksapce上的屏数

本文介绍如何将 Android 1.6 的 Launcher 默认屏幕数量从 3 个增加到 5 个的方法。涉及 Launcher.java、launcher.xml 和 Workspace.java 的修改,以及 default_workspace.xml 中的调整。此外,还解释了自定义属性 declare-styleable 的用法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

2011.06.09——— android 1.6 launcher研究之修改worksapce上的屏数

参考:[url]http://blog.youkuaiyun.com/fzh0803/archive/2011/03/26/6279995.aspx[/url]
[url]http://gqdy365.iteye.com/blog/897638[/url]
[url]http://www.cnblogs.com/playing/archive/2011/03/26/1996209.html[/url]

android1.6的版本有3个屏 需要把它改为5个屏 需要修改的地方 如下

1、Launcher.java

static final int SCREEN_COUNT = 5;
static final int DEFAULT_SCREN = 2;


2、launcher.xml

<com.lp.launcher.Workspace
android:id="@+id/workspace"
android:layout_width="fill_parent"
android:layout_height="fill_parent"

launcher:defaultScreen="2">//从0开始

<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.lp.launcher.Workspace>


defaultScreen 修改为2 然后 加两个<include />

然后 修改默认显示的屏

3、Workspace.java

修改构造方法里面的
mDefaultScreen = a.getInt(R.styleable.Workspace_defaultScreen, 2);//从0开始


这时 基本上已经可以显示5个屏幕了 默认的屏也是第三个屏了 但是进去后 默认显示的屏什么也没有 我们需要把组建都挪到默认屏上去

4、default_workspace.xml

修改所有的 launcher:screen 为 2

launcher:screen="2"


修改完这个后 如果你不是make到源码 而是以app的方式安装到手机上的话 就必须先卸载原有的这个程序 然后在部署

但是 这里有一个问题 我们上次修改的标记 也需要修改

5、home_arrows_left.xml home_arrows_right.xml

<level-list xmlns:android="http://schemas.android.com/apk/res/android">

<item android:maxLevel="0" android:drawable="@android:color/transparent" />
<item android:maxLevel="1" android:drawable="@drawable/home_arrows_left_1" />
<item android:maxLevel="2" android:drawable="@drawable/home_arrows_left_2" />
<item android:maxLevel="3" android:drawable="@drawable/home_arrows_left_3" />
<item android:maxLevel="4" android:drawable="@drawable/home_arrows_left_4" />

</level-list>

<level-list xmlns:android="http://schemas.android.com/apk/res/android">

<item android:maxLevel="0" android:drawable="@drawable/home_arrows_right_4" />
<item android:maxLevel="1" android:drawable="@drawable/home_arrows_right_3" />
<item android:maxLevel="2" android:drawable="@drawable/home_arrows_right_2" />
<item android:maxLevel="3" android:drawable="@drawable/home_arrows_right_1" />
<item android:maxLevel="4" android:drawable="@android:color/transparent" />

</level-list>


大功告成 over

[b]最后 说一个期间的一个知识 [/b]
[color=red]自定义控件的属性 declare-styleable[/color]

比如说 我们上面修改的 launcher:defaultScreen="2" 这个就是自定义的属性 因为这属性不是ViewGroup(workspace类是继承于ViewGroup)所定义的属性

1、在\res\values里面的attrs.xml里面定义

<resources>
<declare-styleable name="Workspace">
<!-- The first screen the workspace should display. -->
<attr name="defaultScreen" format="integer" />
</declare-styleable>

<!-- CellLayout specific attributes. These attributes are used to customize
a CellLayout view in XML files. -->
<declare-styleable name="CellLayout">
<!-- The width of a single cell -->
<attr name="cellWidth" format="dimension" />
<!-- The height of a single cell -->
<attr name="cellHeight" format="dimension" />
<!-- Padding to apply at the start of the long axis -->
<attr name="longAxisStartPadding" format="dimension" />
<!-- Padding to apply at the end of the long axis -->
<attr name="longAxisEndPadding" format="dimension" />
<!-- Padding to apply at the start of the short axis -->
<attr name="shortAxisStartPadding" format="dimension" />
<!-- Padding to apply at the end of the short axis -->
<attr name="shortAxisEndPadding" format="dimension" />
<!-- Number of cells on the short axis of the CellLayout -->
<attr name="shortAxisCells" format="integer" />
<!-- Number of cells on the long axis of the CellLayout -->
<attr name="longAxisCells" format="integer" />
</declare-styleable>
</resources>


2、layout.xml引用

先申明xmlns:launcher="http://schemas.android.com/apk/res/com.lp.launcher"(R.java),
这样就可以使用launcher:defaultScreen。


3、java文件取值
       public Workspace(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);

TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.Workspace, defStyle, 0);
mDefaultScreen = a.getInt(R.styleable.Workspace_defaultScreen, 2);
a.recycle();

initWorkspace();
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值