How to extend a view's touch area

Bernd picture Bernd · Mar 12, 2012 · Viewed 16.8k times · Source

I have a vertical LinearLayout. It shall act as a quick jump bar. So the width is very small and the height matches nearly the whole screen height. When I touch it and move around inside, everything is fine. That means, my onTouchEvent() is called and I can get (and follow) the position of the finger. But since the bar is not very wide, the user can easily drift outside of that view. So it would be necessary to let the user continue the movement even when outside the view. In fact the same thing like a ListView does.

I don't know why a ListView's onTouchEvent() is called even when outside the ListView, but not in case of my LinearLayout. I tracked it down back to the dispatchTouchEvent(). Here the situation is the same that method is always called for the ListView (even when outside) but not in case of the LinearLayout (when moving outside).

I'd be very happy if someone could give me a hint. Thanks a lot!

Bernd

Answer

Tim picture Tim · Mar 12, 2012

You could use Android's TouchDelegate feature. It supports a bigger touch area for single views. Here is an example: https://stackoverflow.com/a/1343796/636579