1

I am using onFling in my views to get a swipe to next activity. However this does not work if the view has a scrollview surrounding it.

Apparently it absorbs the gestures and stops my onFling.

Is there anyway around this issue?

3 Answers 3

3

You are right, ScrollView "steals" the gesture because of it's inherit functionality. I've worked around this before by applying the onTouchListener to the ScrollView itself instead of its immediate parent view.

Sign up to request clarification or add additional context in comments.

3 Comments

how do I do this? do I find the ScrollView threw id and hook it up?
Yes, grab the ScrollView object and use the setOnTouchListener()
after searching for a while, this was the best solution i found to this issue.
2

Check this piece of code: (Override ScrollView's dispatchTouchEvent)

public class yourScrollView extends ScrollView{ //constructors and everything //You might want to pass your GestureDetector (of course) @Override public boolean dispatchTouchEvent(MotionEvent ev){ super.dispatchTouchEvent(ev); return myGestureDetector.onTouchEvent(ev); } } 

4 Comments

Do I just put it in the same activity? I think I tried this but it did not seem to work.
no you should create a class yourScrollView extends ScrollView and this code in it
- then I use that class instead of the ScrollView in the xml layout?
any hints as to what is the best way to pass the GestureDector?
0

I can't comment answers so I write a new one. I found that overriding the dispatchTouchEvent of ScrollView works well but the gesture handler needs to be called before the super.dispatchTouchEvent as that method could change the event coordinates in some weird way. In particular I have seen the Y value jumping when trying to vertically scroll past the end of the view. Calling the gesture handler before the scroll view handling will let it use the scroll view coordinates and not the internal scrolled ones.

So:

public class yourScrollView extends ScrollView{ //constructors and everything @Override public boolean dispatchTouchEvent(MotionEvent ev){ return myGestureDetector.onTouchEvent(ev) | super.dispatchTouchEvent(ev); } } 

Elements in the scroll view react as long as the view does not start scrolling, but the gestures are correctly detected.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.