开发者

How to pass touch events from child view to parent?

I'm trying to implement a drag and drop functionality in an Android application. The drag part is done, the one thing left is to figure out where the dragged view will be dropped? On which view, to be more precise. Here's the onTouch function of my dragged view:

public boolean onTouch(View v, MotionEvent event) {
  // Is the event inside of this view?
  if (!mRegion.contains((int) event.getX(), (int) event.getY())) {
   return false;
  }

  if (event.getAction() == MotionEvent.ACTION_DOWN) {
   ...
   System.out.println("**** IMAGE DRAG STARTED!");
   return true;
  } else if (event.getAction() == MotionEvent.ACTION_MOVE) {
                        ...
   this.invalidate();
   return true;   
  } else if (event.getAction() == MotionEvent.ACTION_UP){
   System.out.println("**** ICON DRAG E开发者_StackOverflow中文版NDED!");
   return false;
  } else {
   return true;
  }
 }

All motion events are handled except the ACTION_UP (the moment when the view is released). The question is how should I make this event to be called in the parent (pass it to the parent's onTouch handler), so I can find out where it was dropped. I have implemented onTouch handling in the parent but no event is caught.

Thanks.


Override onInterceptTouchEvent(MotionEvent event)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜