修改Lanucher屏幕数

来源:互联网 发布:达内 网络培训和 编辑:程序博客网 时间:2024/06/10 08:37

   首先,在Launcher.java代码中,第125行

[java] view plaincopy
  1. static final int SCREEN_COUNT = 5;  
  2. static final int DEFAULT_SCREEN = 2;//第一页是从0开始计数,这里是把第三个页面作为默认首页  

第一个参数定义屏幕个数,第一个参数是默认的首页。在这里,你可以做出自己的修改。但是,仅这点修改,远远不够,我们看一下launcher.xml

[html] view plaincopy
  1. <com.android.launcher2.DragLayer  
  2.     xmlns:android="http://schemas.android.com/apk/res/android"  
  3.     xmlns:launcher="http://schemas.android.com/apk/res/com.android.launcher"  
  4.   
  5.     android:id="@+id/drag_layer"  
  6.     android:layout_width="match_parent"  
  7.     android:layout_height="match_parent">  
  8.   
  9.     <include layout="@layout/all_apps" />  
  10.   
  11.     <!-- The workspace contains 3 screens of cells -->  
  12.     <com.android.launcher2.Workspace  
  13.         android:id="@+id/workspace"  
  14.         android:layout_width="match_parent"  
  15.         android:layout_height="match_parent"  
  16.         android:scrollbars="horizontal"  
  17.         android:fadeScrollbars="true"  
  18.         launcher:defaultScreen="2">  
  19.   
  20.         <include android:id="@+id/cell1" layout="@layout/workspace_screen" />  
  21.         <include android:id="@+id/cell2" layout="@layout/workspace_screen" />  
  22.         <include android:id="@+id/cell3" layout="@layout/workspace_screen" />  
  23.         <include android:id="@+id/cell4" layout="@layout/workspace_screen" />  
  24.         <include android:id="@+id/cell5" layout="@layout/workspace_screen" />  
  25.   
  26.     </com.android.launcher2.Workspace>  

我们可以看到 导入了五个workspace_screen,在这里,参照你上面修改的参数,添加或者删除workspace_screen。在这里,你可能也注意到了

[html] view plaincopy
  1. launcher:defaultScreen="2">  

在这里定义的defaultScreen。

同时,要修改workspace.java中180

[html] view plaincopy
  1. mDefaultScreen = a.getInt(R.styleable.Workspace_defaultScreen, 1);  

和res/xml文件中default_workspace做出相应的修改。这样就基本上可以了。

原创粉丝点击