0

If I swipe left to right or right to left, then I swipe up or down without releasing finger swiping up or down occurred on Scroll Gesture. But I don't want to occur this. I want if am swiping horizontally only horizontal swiping should work not vertical without release finger. I don't know how doing that in android studio, If anyone can help, please help me, thanks in advance.

I have already tried, but can't solve the above problem.

override fun onScroll(event: MotionEvent?, event1: MotionEvent?, distanceX: Float, distanceY: Float): Boolean {

    val sWidth = Resources.getSystem().displayMetrics.widthPixels
    val sHeight = Resources.getSystem().displayMetrics.heightPixels

    val border = 100 * Resources.getSystem().displayMetrics.density.toInt()
    if(event!!.x < border || event.y < border || event.x > sWidth - border || event.y > sHeight - border)
        return false

    if(abs(distanceX) < abs(distanceY)){
        if(event.x < sWidth/2){
            //brightness
            // left side up and down
        }
        else{
            //volume
            // right side up and down
        
    }if (distanceY > distanceX){

       If (distance Y > 0){
            // left to right swipe
      }else{
        // right to left swipe
        }
   }

    return true
}

When I swipe up and down. Left or Right swipe also occur.

Ryzwan
  • 1
  • 1
  • You need to give a lot more information about what types of views and touch or gesture recognizers are involved. As is its impossible to answer your question. – Gabe Sechan Feb 06 '22 at 05:25

1 Answers1

0

Check my answer for a question related to a RecyclerView in a ViewPager. This problem might be similar to yours.

Link to the answer

The answer gives priority to the view which you want to scroll and nothing else!

saman
  • 86
  • 8