2

我正在构建一个应用程序,允许用户使用水平滑动浏览不同的屏幕,但是这些屏幕也包含垂直滚动视图。如果垂直滚动不是 100% 垂直(希望这是有道理的),那么 android 似乎会将垂直滚动检测为水平滑动。

有没有办法禁用垂直滑动,或者降低水平检测的灵敏度?

onFling 类中的代码目前非常基本。

    public boolean onFling(MotionEvent start, MotionEvent finish, float velocityX,
                float velocityY) {
     //Right Swipe
     if (finish.getRawX() < start.getRawX()) {
        Toast.makeText(getApplicationContext(), "Showing Listings For : "+date.getDate(),Toast.LENGTH_SHORT).show();
      }

     if (start.getRawX() < finish.getRawX()) {
        Toast.makeText(getApplicationContext(), "Showing Listings For : "+date.getDate(),Toast.LENGTH_SHORT).show();
      }
    }

- 更新 -

好吧,我最终计算了滑动开始点和结束点之间的垂直差异,这给了我一些东西来确定滑动的垂直程度。它非常基本,但似乎工作正常。

更新后的代码现在看起来像。

    public boolean onFling(MotionEvent start, MotionEvent finish, float velocityX,
                float velocityY) {
     //Right Swipe

     //Caluclate the vertical difference
     float verticalChange = start.getRawY() - finish.getRawY();

     if ((finish.getRawX() < start.getRawX()) && (verticalChange > -40 && verticalChange < 40)) {
        Toast.makeText(getApplicationContext(), "Showing Listings For : "+date.getDate(),Toast.LENGTH_SHORT).show();
      }

     if (start.getRawX() < finish.getRawX()) && (verticalChange > -40 && verticalChange < 40)) {
        Toast.makeText(getApplicationContext(), "Showing Listings For : "+date.getDate(),Toast.LENGTH_SHORT).show();
      }
    }
4

1 回答 1

-1

You could extend your own vertical scrollview that does not trigger the event for a horizontal swipe. Of course, then you would have to swipe on a part that is not the scroll view.

--Extra Comment ---Have you tested this on various phones/devices? You may find yourself having different results.

于 2013-02-26T12:47:37.623 回答