October 2017
Intermediate to advanced
294 pages
6h 49m
English
So far, it's not really useful as we can't interact with it. To add interaction, we need to override the onTouchEvent() method from the View, as we have seen in previous chapters.
In our own implementation of onTouchEvent, we are mainly interested in the ACTION_DOWN, ACTION_UP, and ACTION_MOVE events. Let's see the implementation we have done:
private float dragX; private float dragY; private boolean dragged; ... @Override public boolean onTouchEvent(MotionEvent event) { switch(event.getAction()) { case MotionEvent.ACTION_DOWN: dragX = event.getX(); dragY = event.getY(); getParent().requestDisallowInterceptTouchEvent(true); dragged = false; return true; case MotionEvent.ACTION_UP: if (!dragged) { // touching inside the channel ...Read now
Unlock full access