Android: use RealViewSwitcher to switch between views, for example, on the main screen

I am working on a small but enjoyable open source project: A RealViewSwitcher, which allows you to switch between multiple views by performing a horizontal click, as the Android Launcher does. It is simple ViewGroupthat implements onInterceptTouchEventand onTouchEventfor everything to work. In fact, most of the code is taken from the file Workspace.java(line 572 and the following), as well as the two methods of handling touch events - without much change.

However, I do not get this job. My current working class is hosted here (on pastebin, because it's pretty big): http://pastebin.com/8p8GCEZK

If I execute my class (simply by creating it, adding some text elements, and then setting it as the content view for this operation), I get the following output if I make a quick jump:

12-15 23:53:04.797: INFO/RealViewSwitcher(7477): intercept ACTION_DOWN
12-15 23:53:04.797: INFO/RealViewSwitcher(7477): touch ACTION_DOWN
12-15 23:53:04.807: INFO/RealViewSwitcher(7477): touch ACTION_MOVE
12-15 23:53:04.840: INFO/RealViewSwitcher(7477): touch ACTION_MOVE
12-15 23:53:04.867: INFO/RealViewSwitcher(7477): touch ACTION_MOVE
12-15 23:53:04.897: INFO/RealViewSwitcher(7477): touch ACTION_MOVE
12-15 23:53:04.897: INFO/RealViewSwitcher(7477): touch ACTION_UP

Now my problem is: whatever I do, I don't get ACTION_MOVEin my method onInterceptTouchEvent. I read the documentation several times and tried to play with the return values, but I don't get any other events except ACTION_DOWNthere, which is ugly, because the actual code that triggers the transition is in the case ACTION_MOVE.

Can you help me here? An annoying thing that I can’t get: it seems to be implemented in the same way in the official Launcher app. But their code works, I don’t. What am I missing?

+3
3

:

1), false onInterceptTouchEvent:

  •  
  • , , , () onTouchEvent;  
  • - onInterceptTouchEvent

2), true onInterceptTouchEvent:

  • , , ACTION_CANCEL;
  • onTouchEvent onInterceptTouchEvent.

, 1), onInterceptTouchEvent(), 2), , onTouchEvent(), .

1), .

+2

, . , , , ViewGroup "true".

0

, , , . , , Android , . (nonclickable , textview touchhevent)

0

Source: https://habr.com/ru/post/1780553/


All Articles