问题描述
- android luancher 拖动问题
-
需求是根据luancher源码,然后去掉主菜单,吧所有的app显示在桌面上。
public class Launcher extends Activity implements DragSource,DragScroller,AllAppsPaged.InitDragScoller,DropTarget,DragController.DragListenerprivate void setupViews() { final DragController dragController = mDragController; mDragLayer = (DragLayer)findViewById(R.id.drag_layer); m_allApps = (AllAppsPaged)findViewById(R.id.launcher); mDragLayer.setup(this, dragController); m_allApps.setHapticFeedbackEnabled(false); // Setup the workspace dragController.addDragListener(m_allApps); initDragScroller(dragController, m_allApps, mDragLayer); } @Override public void initDragScroller(DragController dragController, AllAppsPaged appsPaged, DragLayer dragLayer) { dragController.setDragScoller(appsPaged); dragController.setScrollView(dragLayer); dragController.setMoveTarget(appsPaged); dragController.addDropTarget(appsPaged); } private DropTarget findDropTarget(int x, int y, int[] dropCoordinates) { final Rect r = mRectTemp; final ArrayList<DropTarget> dropTargets = mDropTargets; final int count = dropTargets.size(); for (int i = count - 1; i >= 0; i--) { DropTarget target = dropTargets.get(i); if (!target.isDropEnabled()) { continue; } target.getHitRect(r); // Convert the hit rect to DragLayer coordinates target.getLocationInDragLayer(dropCoordinates); r.offset(dropCoordinates[0] - target.getLeft(), dropCoordinates[1] - target.getTop()); mDragObject.x = x; mDragObject.y = y; if (r.contains(x, y)) { DropTarget delegate = target.getDropTargetDelegate(mDragObject); if (delegate != null) { target = delegate; target.getLocationInDragLayer(dropCoordinates); } // Make dropCoordinates relative to the DropTarget dropCoordinates[0] = x - dropCoordinates[0]; dropCoordinates[1] = y - dropCoordinates[1]; return target; } } return null; } 在findDropTarget这个函数中,一直返回null,请问是哪里的问题? 以上代码跟原生luancher唯一不同的就是就是setupviews的地方。 原生luancher的代码: // Setup the drag controller (drop targets have to be added in reverse order in prioriyt) dragController.setDragScoller(mWorkspace); dragController.setScrollView(mDragLayer); dragController.setMoveTarget(mWorkspace); dragController.addDropTarget(mWorkspace);
解决方案
http://blog.csdn.net/gf771115/article/details/8152837
时间: 2024-10-28 09:50:07