Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Android Custom Touch Handling

Android Custom Touch Handling

Want to make the ScrollView not scrollable?
Want to have 2 (or more) views receiving a click at the same time?
Come to this Android Saigon Meetup, where we share about these techiques to help you learn how Android deals with user's gestures.

Avatar for thuutin

thuutin

May 11, 2016
Tweet

Other Decks in Programming

Transcript

  1. public boolean dispatchTouchEvent(MotionEvent ev) { for(View child : childrenViews) {

    if(child.dispatchTouchEvent(ev)) { return true; } } return super.dispatchTouchEvent(ev); } ViewGroup - dispatchTouchEvent
  2. View.java - dispatchTouchEvent if (!result && onTouchEvent(event)) { result =

    true; } if (mOnTouchListener != null && mOnTouchListener.onTouch(this, event)) { result = true; } public boolean dispatchTouchEvent(MotionEvent event) { result = false; return result; }
  3. return super.dispatchTouchEvent(ev); } ViewGroup - dispatchTouchEvent - with intercept public

    boolean dispatchTouchEvent(MotionEvent ev) { for(View child : children){
 if(child.dispatchTouchEvent(ev)) return true; } if(!onInterceptTouchEvent()){ }
  4. public static void main(String[] args){ for( int i = 0;

    i >= 0; i++){ System.out.println(“Demos"); } }