简体   繁体   English

Android Developemnt:降低水平滑动灵敏度或关闭垂直滑动

[英]Android Developemnt: Decrease horizontal swipe sensitivity OR turn off vertical swiping

I am building an app that allows the user to navigate through different screens using horizontal swipes, however these screens also contain a vertical scrollview. 我正在构建一个允许用户使用水平滑动在不同屏幕之间导航的应用程序,但是这些屏幕也包含垂直滚动视图。 It appears that android detects vertical scrolling as horizontal swipes if the vertical scroll isn't 100% vertical (hope that makes sense). 如果垂直滚动不是100%垂直(希望如此),则android似乎会将垂直滚动检测为水平滑动。

Is there anyway to disable vertical swiping, or decrease the sensitivity of the horizontal detection? 无论如何,是否可以禁用垂直滑动或降低水平检测的灵敏度?

The code within the onFling class is pretty basic at the moment like so. 目前,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();
      }
    }

-- Update -- -更新-

Well I ended up calculating the vertical difference bewtween the start and end points of the swipe, which gave me a something to use to determine how vertical a swipe was. 好了,我最终计算了滑动起点和终点之间的垂直差,这给了我一些信息来确定滑动的垂直度。 Its pretty basic but seems to work ok. 它很基本,但似乎可以。

The updated code now looks like. 更新后的代码现在看起来像。

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

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? --Extra Comment ---您是否已在各种手机/设备上测试过? You may find yourself having different results. 您可能会发现自己有不同的结果。

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

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