2 u013169022 u013169022 于 2016.02.04 15:21 提问

android luancher 拖动问题

需求是根据luancher源码,然后去掉主菜单,吧所有的app显示在桌面上。
public class Launcher extends Activity implements DragSource,DragScroller,AllAppsPaged.InitDragScoller,DropTarget,DragController.DragListener

private 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);

1个回答

devmiao
devmiao   Ds   Rxr 2016.02.04 21:46
Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!