0

I'm trying to implement Catch onTouch event by parent, handle it and pass to children butt failed to do that.

Gist of full 2d scroll code is here

what I have tried:

Override the method dispatchTouchEvent, and sent the MotionEvent to a GestureDetector

     @Override
     public boolean dispatchTouchEvent (MotionEvent ev) {

    // return super.dispatchTouchEvent(ev);

     boolean result = super.dispatchTouchEvent(ev);
     if (gestureDetector.onTouchEvent(ev)) {
            return result;
       } 
       //If not scrolling vertically (more y than x), don't hijack the event.
        else {
            return false;
       }

}

Activity:

   setContentView(R.layout.activity_fullscreen);

    final View contentView = findViewById(R.id.fullscreen_content);

    android.support.v4.app.FragmentManager fm = getSupportFragmentManager();
    ctx = this;

   ShapeDrawableView     animView = new ShapeDrawableView(this, fm, ctx);//customview



    ((ViewGroup) contentView).addView(animView);

Layout:

<view
   class="com.example.astream.TwoDScrollView" 
   android:id="@+id/fullscreen_content"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
     android:gravity="center" />
Community
  • 1
  • 1
LOG_TAG
  • 19,894
  • 12
  • 72
  • 105

1 Answers1

2

Can't inspect in great detail right now, but this stands out as an issue:

//If not scrolling vertically (more y than x), don't hijack the event.
else {
    return false;
}

returning false isn't necessarily true here; one of your child views may have actually handled the event and needed to let somebody know... I think you need to do something more like this:

@Override
public boolean dispatchTouchEvent (MotionEvent ev) {
    gestureDetector.onTouchEvent(ev);

    return super.dispatchTouchEvent(ev);
}
JRaymond
  • 11,625
  • 5
  • 37
  • 40
  • Thanks, I have moved to some other logic... can you help me on this https://stackoverflow.com/questions/26376601/how-to-update-android-shapedrawable-bounds-changes-after-implimenting-scroller-w – LOG_TAG Oct 15 '14 at 07:24