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

参考: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;


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

最后 说一个期间的一个知识
自定义控件的属性 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>


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();    }

更多相关文章

  1. Android6.0 Launcher3 修改app字体大小
  2. Android(安卓)的系统属性(SystemProperties)设置分析
  3. android中动画的使用
  4. ListView自动滚动方法
  5. Android(安卓)开发笔记1
  6. Android(安卓)FlexboxLayout使用方式
  7. Android--EditText控件属性汇总
  8. Android修改触摸按键震动强弱
  9. Android中的Logcat方法查看内核的日志

随机推荐

  1. Android(安卓)重力感应 翻转页面造成Acti
  2. Android在应用中固定屏幕方向
  3. Android文档-开发者指南-第一部分:入门-中
  4. Android(安卓)的GUI 系统
  5. Eclipse安装Android教程
  6. Android(安卓)Makefile中是 如何识别 TAR
  7. android APP安装支持安装到SDCard
  8. [转]Android(安卓)技术专题系列之九 -- 图
  9. Android(安卓)移动平台概述
  10. android入门1:有关布局与activity数据传递