在Launcher.java
protected boolean hasCustomContentToLeft() {
//return false;
return true;//负一屏开关打开 wanchengguo 20180424
}
/**
* To be overridden by subclasses to populate the custom content container and call
* {@link #addToCustomContentPage}. This will only be invoked if
* {@link #hasCustomContentToLeft()} is {@code true}.
*/
protected void populateCustomContentContainer() {
/*wanchengguo 负一屏加载布局 20180424 begin*/
View negativeviews = getLayoutInflater().inflate(R.layout.my_negative_layout, null);//加载的布局
initData();//数据、view初始化
addToCustomContentPage(negativeviews, mWorkspace.getCustomContentCallbacks(), "custom view");
/*wanchengguo 负一屏加载布局 20180424 end*/
}
默认显示左屏:
默认显示哪一屏设置方法: launcher:defaultScreen
res/layout/launcher.xml// Launcher.java 加载的布局
.....
<com.android.launcher3.Workspace
android:id="@+id/workspace"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
launcher:defaultScreen="@integer/config_workspaceDefaultScreen" />
.......
Workspace.java
public void createCustomContentContainer() {
CellLayout customScreen = (CellLayout)
mLauncher.getLayoutInflater().inflate(R.layout.workspace_screen, null);
customScreen.disableBackground();
customScreen.disableDragTarget();
mWorkspaceScreens.put(CUSTOM_CONTENT_SCREEN_ID, customScreen);
mScreenOrder.add(0, CUSTOM_CONTENT_SCREEN_ID);
// We want no padding on the custom content
customScreen.setPadding(0, 0, 0, 0);
addFullScreenPage(customScreen);
// Ensure that the current page and default page are maintained.
mDefaultPage = mOriginalDefaultPage /*+ 1*/;//添加左屏时 默认显示页数不加1,目的是让左屏是默认显示页 当设置默认显示屏为0时 wanchengguo 20180428
// Update the custom content hint
if (mRestorePage != INVALID_RESTORE_PAGE) {
mRestorePage = mRestorePage + 1;
} else {
setCurrentPage(getCurrentPage() + 1);
}
}