Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ScrollView: Pass touch events to children

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?

like image 549
Toast Avatar asked Jan 26 '13 16:01

Toast


2 Answers

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.

like image 78
Toast Avatar answered Nov 15 '22 03:11

Toast


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.

like image 30
Brandon Romano Avatar answered Nov 15 '22 03:11

Brandon Romano