Launcher中WorkSpace图标的位置固定

http://blog.csdn.net/dande618/article/details/9248793?locationNum=7 这篇博客有说到,大家可以参考一下。这里我只是给大家说具体位置。

博客说到的canReorder = false 这个属性,这个是在CellLayout.这个类中,大家可以搜索到。

还提到这个属性在那个方法中调用的,都是在这一个类中,搜索就可以了。

将这两个方法:一:private boolean rearrangementExists(int cellX, int cellY, int spanX, int spanY, int[] direction,
            View ignoreView, ItemConfiguration solution) {
        // Return early if get invalid cell positions
        if (cellX < 0 || cellY < 0) return false;

        mIntersectingViews.clear();
        mOccupiedRect.set(cellX, cellY, cellX + spanX, cellY + spanY);

        // Mark the desired location of the view currently being dragged.
        if (ignoreView != null) {
            CellAndSpan c = solution.map.get(ignoreView);
            if (c != null) {
                c.x = cellX;
                c.y = cellY;
            }
        }
        Rect r0 = new Rect(cellX, cellY, cellX + spanX, cellY + spanY);
        Rect r1 = new Rect();
        for (View child: solution.map.keySet()) {
            if (child == ignoreView) continue;
            CellAndSpan c = solution.map.get(child);
            LayoutParams lp = (LayoutParams) child.getLayoutParams();
            r1.set(c.x, c.y, c.x + c.spanX, c.y + c.spanY);
            if (Rect.intersects(r0, r1)) {
                if (!lp.canReorder) {
                    return false;
                }
                mIntersectingViews.add(child);
            }

        }

.......省略....

二:

 private boolean pushViewsToTempLocation(ArrayList views, Rect rectOccupiedByPotentialDrop,
            int[] direction, View dragView, ItemConfiguration currentState) {

......省略...

    while (pushDistance > 0 && !fail) {
            for (View v: currentState.sortedViews) {
                // For each view that isn't in the cluster, we see if the leading edge of the
                // cluster is contacting the edge of that view. If so, we add that view to the
                // cluster.
                if (!cluster.views.contains(v) && v != dragView) {
                    if (cluster.isViewTouchingEdge(v, whichEdge)) {
                        LayoutParams lp = (LayoutParams) v.getLayoutParams();
                        if (!lp.canReorder) {
                            // The push solution includes the all apps button, this is not viable.
                            fail = true;
                            break;
                        }
                        cluster.addView(v);
                        CellAndSpan c = currentState.map.get(v);

                        // Adding view to cluster, mark it as not occupied.
                        markCellsForView(c.x, c.y, c.spanX, c.spanY, mTmpOccupied, false);
                    }
                }

            }

......省略...


注释掉一后:图标可以被直接挤开。

注释掉二后:图标可以被间接挤开,就是挤压相邻的另一个图标。

大家可以试一下哦,注释了WorkSpace上面的图标就不能被挤开,直接固定了,如果你要把其他的图标移动到另一个图标的上面,这时候就会形成一个文件夹,将两个图标装在一起。

你可能感兴趣的:(Launcher)