Fling gesture detection on grid layout

前端 未结 18 1548
遥遥无期
遥遥无期 2020-11-21 04:38

I want to get fling gesture detection working in my Android application.

What I have is a GridLayout that contains 9 ImageView

18条回答
  •  感情败类
    2020-11-21 05:30

    One of the answers above mentions handling different pixel density but suggests computing the swipe parameters by hand. It is worth noting that you can actually obtain scaled, reasonable values from the system using ViewConfiguration class:

    final ViewConfiguration vc = ViewConfiguration.get(getContext());
    final int swipeMinDistance = vc.getScaledPagingTouchSlop();
    final int swipeThresholdVelocity = vc.getScaledMinimumFlingVelocity();
    final int swipeMaxOffPath = vc.getScaledTouchSlop();
    // (there is also vc.getScaledMaximumFlingVelocity() one could check against)
    

    I noticed that using these values causes the "feel" of fling to be more consistent between the application and rest of system.

提交回复
热议问题