1 public boolean addViewToCellLayout(View child, int index, int childId, LayoutParams params, 2 boolean markCells) { 3 final LayoutParams lp = params; 4 5 // Hotseat icons - remove text 6 if (child instanceof BubbleTextView) { 7 BubbleTextView bubbleChild = (BubbleTextView) child; 8 bubbleChild.setTextVisibility(!mIsHotseat); 9 } 10 11 child.setScaleX(getChildrenScale()); 12 child.setScaleY(getChildrenScale()); 13 14 // Generate an id for each view, this assumes we have at most 256x256 cells 15 // per workspace screen 16 if (lp.cellX >= 0 && lp.cellX <= mCountX - 1 && lp.cellY >= 0 && lp.cellY <= mCountY - 1) { 17 // If the horizontal or vertical span is set to -1, it is taken to 18 // mean that it spans the extent of the CellLayout 19 if (lp.cellHSpan < 0) lp.cellHSpan = mCountX; 20 if (lp.cellVSpan < 0) lp.cellVSpan = mCountY; 21 22 child.setId(childId); 23 24 mShortcutsAndWidgets.addView(child, index, lp); 25 26 if (markCells) markCellsAsOccupiedForView(child); 27 28 return true; 29 } 30 return false; 31 }
allapp这就是加载每个icon到view的那个位置
1、将就的地方 launcher.java
static int[] getSpanForWidget(Context context, ComponentName component, int minWidth, int minHeight) { // Rect padding = AppWidgetHostView.getDefaultPaddingForWidget(context, component, null); Rect padding = new Rect(20, 20, 300, 300); // We want to account for the extra amount of padding that we are adding to the widget // to ensure that it gets the full amount of space that it has requested int requiredWidth = minWidth + padding.left + padding.right; int requiredHeight = minHeight + padding.top + padding.bottom; return CellLayout.rectToCell(requiredWidth, requiredHeight, null); }