5

I made a "joystick" out of an ImageView. It is inside a ScrollView.

It works without the ScrollView but inside the ScrollView it does not receive TouchEvents for vertical movement.

How can I stop the ScrollView from blocking the touch event?

ardiien
  • 767
  • 6
  • 26
Toast
  • 596
  • 2
  • 19
  • 39

3 Answers3

6

You're going to want to toggle this on and off as needed..

getParent().requestDisallowInterceptTouchEvent(true).

I'm not exactly sure why you have the joystick in a scroll view, is the joystick also supposed to be scrolling with the view? If this is what is intended, the route above would be the best solution. If it's not supposed to be scrolling with the view, I'll help you work out a better method of including the joystick in your view.

Suragch
  • 484,302
  • 314
  • 1,365
  • 1,393
Brandon Romano
  • 1,022
  • 1
  • 13
  • 21
  • This has no effect, regardless of whether I call it for the ScrollView or its parent, with true or false. I need a ScrollView because the user could add as many joysticks as he wants. It would be ok to disable scrolling for the ImageView but I want the ScrollView to be scrollable touching other views. – Toast Jan 26 '13 at 17:25
  • No effect? You should be calling it joystickView.getParent().requestDisallowInterceptTouchEvent(true)... Is this how you're calling it? Take a look at [This](http://stackoverflow.com/questions/2229178/disable-scrollview-action) post. I disagree with the elegance of the top rated answer, but that should also do the job. – Brandon Romano Jan 26 '13 at 17:51
  • Okay I implemented it like in the link. Now it does not scroll anymore. But vertical movements are still not detected by the ImageView (while horizontal movements are detected). – Toast Jan 26 '13 at 17:59
6

I found a solution here.

I created a custom ScrollView class that has a boolean indicating whether it is locked. The onInterceptTouchEvent method is overridden:

@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
    if (!mScrollable) return false;
    return super.onInterceptTouchEvent(ev);
}

When the joystick is touched (ACTION_DOWN), the custom ScrollView is locked. At the ATCTION_UP event it is unlocked.

Community
  • 1
  • 1
Toast
  • 596
  • 2
  • 19
  • 39
-1

simple answer is here : https://stackoverflow.com/a/34436589/3818437

Declare your ScrollView not clickable / focusable by using

android:clickable="false" and android:focusable="false"

or

v.setClickable(false) and v.setFocusable(false).

The click events should be dispatched to the ScrollView's parent now.

mhdjazmati
  • 4,152
  • 1
  • 26
  • 37