royqazwsx 2016-02-04 07:21 采纳率: 0%
浏览 1527

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 2016-02-04 13:46
    关注
    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog