一.CellLayout是什么
在前面的 Android4.4-Launcher源码分析系列之Launcher介绍分析了Launcher的布局,CellLayout继承自ViewGroup,
一个Workspace由多个CellLayout组成,每一个CellLayout负责里面图标(favorite)和widget的显示.说白了,我们滑动屏幕的每一页就是一个CellLayout.
二、CellLayout的布局
CellLayout的布局为workspace_screen.xml.
<com.android.launcher3.CellLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:launcher="http://schemas.android.com/apk/res-auto/com.android.launcher3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hapticFeedbackEnabled="false"
launcher:maxGap="@dimen/workspace_max_gap" />
hapticFeedbackEnabled是触力反馈的意思,比如说按一下震动就是触力反馈.
maxGap是CellLayout中元素(图标,widget)之间的最大距离
除了这两个属性其他的属性都是在代码中定义的.
WorkSpace是在insertNewWorkspaceScreen方法中加载CellLayout的布局的.
/**
* @param screenId 屏幕Id
* @param insertIndex 插入的序号
* 插入新的屏幕
*/
public long insertNewWorkspaceScreen(long screenId, int insertIndex) {
System.out.println(".............WorkSpace.......增加一页");
if (mWorkspaceScreens.containsKey(screenId)) {
throw new RuntimeException("Screen id " + screenId + " already exists!");
}
//加载CellLayout的布局
CellLayout newScreen = (CellLayout)mLauncher.getLayoutInflater().inflate(R.layout.workspace_s