现在的位置: 首页 > 综合 > 正文

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

2013年10月27日 ⁄ 综合 ⁄ 共 7113字 ⁄ 字号 评论关闭

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

Java代码 复制代码 收藏代码
  1. static final int SCREEN_COUNT = 5;   
  2. static final int DEFAULT_SCREN = 2;  

2、launcher.xml

Java代码 复制代码 收藏代码
  1. <com.lp.launcher.Workspace   
  2.         android:id="@+id/workspace"  
  3.         android:layout_width="fill_parent"  
  4.         android:layout_height="fill_parent"  
  5.   
  6.         launcher:defaultScreen="2">//从0开始
      
  7.   
  8.         <include android:id="@+id/cell1" layout="@layout/workspace_screen" />   
  9.         <include android:id="@+id/cell2" layout="@layout/workspace_screen" />   
  10.         <include android:id="@+id/cell3" layout="@layout/workspace_screen" />   
  11.         <include android:id="@+id/cell4" layout="@layout/workspace_screen" />   
  12.         <include android:id="@+id/cell5" layout="@layout/workspace_screen" />   
  13.   
  14. </com.lp.launcher.Workspace>  

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

然后 修改默认显示的屏

3、Workspace.java

修改构造方法里面的

Java代码 复制代码 收藏代码
  1. mDefaultScreen = a.getInt(R.styleable.Workspace_defaultScreen, 2);//从0开始  

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

4、default_workspace.xml

修改所有的 launcher:screen 为 2 

Java代码 复制代码 收藏代码
  1. launcher:screen="2"  

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

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

5、home_arrows_left.xml home_arrows_right.xml

Java代码 复制代码 收藏代码
  1. <level-list xmlns:android="http://schemas.android.com/apk/res/android">   
  2.   
  3.     <item android:maxLevel="0" android:drawable="@android:color/transparent" />   
  4.     <item android:maxLevel="1" android:drawable="@drawable/home_arrows_left_1" />   
  5.     <item android:maxLevel="2" android:drawable="@drawable/home_arrows_left_2" />   
  6.     <item android:maxLevel="3" android:drawable="@drawable/home_arrows_left_3" />   
  7.     <item android:maxLevel="4" android:drawable="@drawable/home_arrows_left_4" />   
  8.        
  9. </level-list>   
  10.   
  11. <level-list xmlns:android="http://schemas.android.com/apk/res/android">   
  12.        
  13.     <item android:maxLevel="0" android:drawable="@drawable/home_arrows_right_4" />   
  14.     <item android:maxLevel="1" android:drawable="@drawable/home_arrows_right_3" />   
  15.     <item android:maxLevel="2" android:drawable="@drawable/home_arrows_right_2" />   
  16.     <item android:maxLevel="3" android:drawable="@drawable/home_arrows_right_1" />   
  17.     <item android:maxLevel="4" android:drawable="@android:color/transparent" />   
  18.       
  19. </level-list>  

大功告成 over

最后 说一个期间的一个知识
自定义控件的属性 declare-styleable

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

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

Java代码 复制代码 收藏代码
  1. <resources>   
  2. <declare-styleable name="Workspace">   
  3.         <!-- The first screen the workspace should display. -->   
  4.         <attr name="defaultScreen" format="integer"  />   
  5.     </declare-styleable>   
  6.        
  7.     <!-- CellLayout specific attributes. These attributes are used to customize   
  8.          a CellLayout view in XML files. -->   
  9.     <declare-styleable name="CellLayout">   
  10.         <!-- The width of a single cell -->   
  11.         <attr name="cellWidth" format="dimension"  />   
  12.         <!-- The height of a single cell -->   
  13.         <attr name="cellHeight" format="dimension"  />   
  14.         <!-- Padding to apply at the start of the long axis -->   
  15.         <attr name="longAxisStartPadding" format="dimension"  />   
  16.         <!-- Padding to apply at the end of the long axis -->   
  17.         <attr name="longAxisEndPadding" format="dimension"  />   
  18.         <!-- Padding to apply at the start of the short axis -->   
  19.         <attr name="shortAxisStartPadding" format="dimension"  />   
  20.         <!-- Padding to apply at the end of the short axis -->   
  21.         <attr name="shortAxisEndPadding" format="dimension"  />   
  22.         <!-- Number of cells on the short axis of the CellLayout -->   
  23.         <attr name="shortAxisCells" format="integer" />   
  24.         <!-- Number of cells on the long axis of the CellLayout -->   
  25.         <attr name="longAxisCells" format="integer" />   
  26.     </declare-styleable>   
  27. </resources>  

2、layout.xml引用

Java代码 复制代码 收藏代码
  1. 先申明xmlns:launcher="http://schemas.android.com/apk/res/com.lp.launcher"(R.java),   
  2. 这样就可以使用launcher:defaultScreen。  

3、java文件取值

Java代码 复制代码 收藏代码
  1.    public Workspace(Context context, AttributeSet attrs, int defStyle) {   
  2.     super(context, attrs, defStyle);   
  3.   
  4.     TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.Workspace, defStyle, 0);   
  5.     mDefaultScreen = a.getInt(R.styleable.Workspace_defaultScreen, 2);   
  6.     a.recycle();   
  7.   
  8.     initWorkspace();   
  9. }  

抱歉!评论已关闭.