简体   繁体   English

手指拖动摩托罗拉机器人

[英]Finger drag on motorola droid

I am programming an android application and my "testing" device is a Motorola Milestone (Droid). 我正在编写一个android应用程序,而我的“测试”设备是Motorola Milestone(Droid)。 I have done a grid that scroll like the iPhone home menu ( with "points"). 我做了一个像iPhone主菜单一样滚动的网格(带有“点”)。 I got two problems: 我遇到两个问题:

  1. The first one : the drag only works on the Android Device Emulator and don't on the Droid! 第一个:拖动仅在Android设备仿真器上有效,而在Droid上无效! (Maybe the multi-touch screen is a problem?) (也许多点触摸屏有问题吗?)
  2. The drag is too responsible, and flip views sometimes one by one (this is ok) and sometimes 2 by 2 or 3 by 3! 拖动操作过于负责,有时会一一翻转视图(可以),有时会二乘2或三乘3! That is clearly problematic! 这显然是有问题的!

Here is the code of my OnTouch method: 这是我的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;
}

Thanks for your help! 谢谢你的帮助!

Update : It doesn't work anymore on the Google Nexus One! 更新:它在Google Nexus One上不再起作用!

If you consider the onTouch event being handled you should return true to indicate that it should not propagate any further. 如果您认为正在处理onTouch事件,则应返回true以指示它不应进一步传播。 If you return false other listeners will receive it and might do something about it, which could be causing this. 如果返回false,则其他侦听器将收到它并可能对此做出处理,这可能是导致此问题的原因。 How about trying: 如何尝试:

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

Ok, I manage to have a good drag with this: 好的,我设法做到了:

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

Now, I get an other big problem : I can't click on my grid! 现在,我遇到了另一个大问题:我无法单击网格!

The code of my grid is : 我的网格代码是:

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

I don't now how to get again the clicks on my grid... 我现在不知道如何再次获得网格上的点击次数...

If someone have an idea... 如果有人有主意...

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

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