0

In a ScrollView, I want to implement horizontal scrolling. To do so, I listen to the MotionEvents sent when fingers touch the screen or move onto it. It works pretty well, except when I unwillingly combine a vertical move with the horizontal one. I noticed that the vertical move interrupts the string of ACTION_MOVE by placing an ACTION_CANCEL event. And after it, no more ACTION_MOVE events are generated.

How can I do to prevent those vertical moves from cancelling the emission of ACTION_MOVE events?

Thanks in advance for the time you will spend trying to help me.

Zelig63
  • 1,592
  • 1
  • 23
  • 40

2 Answers2

1

You want the child view inside the vertical Scrollview to call this line of code:

getParent().requestDisallowInterceptTouchEvent(true);

Check out this SO post for more: Let parent View assume MotionEvents if child returns false

Community
  • 1
  • 1
Salil Pandit
  • 1,498
  • 10
  • 13
  • PS. Frank makes a point, I just assumed you have vertical views that needed scroll and that one of the child views needed to scroll horizontally. If you were in fact trying to horizontal scroll a `ScrollView` then follow his advice... – Salil Pandit Jul 15 '12 at 06:29
  • In fact, I want to have both vertical and horizontal scroll enabled. For the vertical scroll, I'm very pleased with the way the `ScrollView`does the job. And for the horizontal scroll, I'm doing it with my own code. I "just" want to temporarily disable vertical scroll, the time for the horizontal scroll to take place without being disturbed. – Zelig63 Jul 15 '12 at 17:27
  • Does this mean there are several child views that are stacked ontop of each other and when you bring one into view and try and scroll it horizantally only it should? or the entire view thats wrapped in a scroll view is doing so? Can you post your xml layout? That will make it easier to understand what you are trying to move... – Salil Pandit Jul 16 '12 at 22:55
  • In the layout file, I declare a custom view based on a `ScrollView`. In the `onResume`function of my `Activity`, I add a new custom view belonging to a class which depends on the options choosen by the user. But it's always a class based on a `ScrollView`. The vertical scroll is handled by the `ScrollView` and the horizontal one is handled by my code : I offset what I draw in the `onDraw`method in accordance with the move of the finger on the screen. – Zelig63 Jul 17 '12 at 15:53
0

Why aren't you just using a HorizontalScrollView That's what these things are built for.

Frank Sposaro
  • 8,511
  • 4
  • 43
  • 64