繁体   English   中英

手指拖动摩托罗拉机器人

[英]Finger drag on motorola droid

我正在编写一个android应用程序,而我的“测试”设备是Motorola Milestone(Droid)。 我做了一个像iPhone主菜单一样滚动的网格(带有“点”)。 我遇到两个问题:

  1. 第一个:拖动仅在Android设备仿真器上有效,而在Droid上无效! (也许多点触摸屏有问题吗?)
  2. 拖动操作过于负责,有时会一一翻转视图(可以),有时会二乘2或三乘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上不再起作用!

如果您认为正在处理onTouch事件,则应返回true以指示它不应进一步传播。 如果返回false,则其他侦听器将收到它并可能对此做出处理,这可能是导致此问题的原因。 如何尝试:

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

好的,我设法做到了:

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

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

如果有人有主意...

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM