【问题标题】:Finger drag on motorola droid摩托罗拉机器人上的手指拖动
【发布时间】:2010-07-19 15:34:07
【问题描述】:

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

  1. 第一个:拖动仅适用于 Android 设备模拟器,不适用于 Droid! (也许多点触控屏幕有问题?)
  2. 拖拽太负责了,有时会一个一个(这没问题)翻转视图,有时是 2 x 2 或 3 x 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 上运行!

【问题讨论】:

    标签: android touch


    【解决方案1】:

    如果您认为正在处理 onTouch 事件,则应返回 true 以指示它不应进一步传播。如果您返回 false,其他侦听器将收到它并可能会对此采取一些措施,这可能会导致这种情况。试试看怎么样:

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

    【讨论】:

      【解决方案2】:

      好的,我成功地解决了这个问题:

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

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

      如果有人有想法...

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2010-09-08
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多