摩托车机器人手指拖动

时间:2010-07-16 07:48:09

标签: android touch

我正在编写一个Android应用程序,我的“测试”设备是摩托罗拉里程碑(Droid)。我做了一个像iPhone主菜单一样滚动的网格(带“点”)。 我有两个问题:

  1. 第一个:拖动仅适用于Android设备模拟器,而不适用于Droid! (也许多点触摸屏有问题?)
  2. 拖拽太负责了,有时候一个接一个地翻转视图(这没关系),有时候2乘2或3乘3!这显然有问题!
  3. 以下是我的OnTouch方法的代码:

    public boolean onTouch(View v, MotionEvent event) {
    
        if (v instanceof GridView){
            int eventaction = event.getAction();
            switch (eventaction) {
            case MotionEvent.ACTION_MOVE:
                if (event.getEdgeFlags()==MotionEvent.EDGE_LEFT){
                    vf2.setInAnimation(this, R.anim.slide_left);
                    vf2.setOutAnimation(this, R.anim.slide_right);
                    vf2.showNext();
                    if (numCurrentPage==2){
                        numCurrentPage= 0;
                    } else {
                        numCurrentPage++;
                    }
                    notifyPageNumber(numCurrentPage);
                }
                if (event.getEdgeFlags()==MotionEvent.EDGE_RIGHT){
                    vf2.setInAnimation(this, R.anim.slide_in);
                    vf2.setOutAnimation(this, R.anim.slide_out);
                    vf2.showPrevious();
                    if (numCurrentPage==0){
                        numCurrentPage= 2;
                    } else {
                        numCurrentPage--;
                    }
                    notifyPageNumber(numCurrentPage);
                }
                break;
            default:
                break;
            }
        }
    
        return false;
    }
    

    感谢您的帮助!

    更新:它在Google Nexus One上不再有用了!

2 个答案:

答案 0 :(得分:0)

如果您认为正在处理onTouch事件,则应返回 true 以指示它不应再传播。如果你返回false,其他的听众都会收到它并可能对它做些什么,这可能会导致这种情况。怎么样尝试:

if (v instanceof GridView){
    ...
    return true;
}
return false;

答案 1 :(得分:0)

好的,我设法有一个很好的拖累:

public boolean onTouch(View v, MotionEvent event) {
    if (v instanceof GridView){
        int eventaction = event.getAction();
        switch (eventaction) {
        case MotionEvent.ACTION_DOWN:
            xStart = event.getX();
            break;
        case MotionEvent.ACTION_UP:
            xEnd = event.getX();
            System.out.println("Start = "+xStart+", End = "+xEnd);
            if (xEnd - xStart > 100){

                vf2.setInAnimation(this, R.anim.slide_in);
                vf2.setOutAnimation(this, R.anim.slide_out);
                vf2.showPrevious();
                if (numPageActuelle==0){
                    numCurrentPage= 2;
                } else {
                    numCurrentPage--;
                }
                notifyPageNumber(numCurrentPage);
            }
            if (xEnd - xStart < -100){
                vf2.setInAnimation(this, R.anim.slide_left);
                vf2.setOutAnimation(this, R.anim.slide_right);
                vf2.showNext();
                if (numPageActuelle==2){
                    numCurrentPage= 0;
                } else {
                    numCurrentPage++;
                }
                notifyPageNumber(numCurrentPage);
            }
            return true;
        default:
            break;
        }
        return true;
    }
    return false;
}

现在,我遇到了另一个大问题:我无法点击我的网格!

我网格的代码是:

private ViewFlipper vf;
......
vf.setOnTouchListener(this);
GridView pageGrid = new GridView(this);

pageGrid.setNumColumns(3);
pageGrid.setAdapter(new ModuleAdapter(this,listPages.get(j)));
pageGrid.setOnTouchListener(this);

vf.addView(pageGrid);

我现在不知道如何再次点击我的网格...

如果有人有想法......

相关问题