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?
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With