参考: http://blog.csdn.net/fzh0803/archive/2011/03/26/6279995.aspx
http://gqdy365.iteye.com/blog/897638
http://www.cnblogs.com/playing/archive/2011/03/26/1996209.html
android1.6的版本有3个屏 需要把它改为5个屏 需要修改的地方 如下
1、Launcher.java
- static final int SCREEN_COUNT = 5;
- static final int DEFAULT_SCREN = 2;
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">
-
- <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>
<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);
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>
<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
最后 说一个期间的一个知识
自定义控件的属性 declare-styleable
比如说 我们上面修改的 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>
<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。
先申明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();
- }