问题
I have two views, the bigger one is on the bottom, and the smaller one is on the top. Show on following picture:
Now I press mouse on view1 (outside view2), then move to view2. I found even if the mouse is inside view2 during the movement, view2 won't get the ACTION_MOVE event. Only view1 can get it.
What I want:
When the mouse is inside view1 and outside view2, let view1 handle the
ACTION_MOVEevent. If the mouse move into view2, then let view2 handle theACTION_MOVEevent.
How to do it?
PS: android version is 2.x
回答1:
It is not possible,but you can do some things else:
Get coordinates of mouse and view2,if mouse is in bounds of view2,try what you want.Or if you want,you can call view2.onTouch method directly,create a touchlistener class for V2,for example V2TouchListener then:
View v2 = ... ;
final V2TouchListener v2t = new V2TouchListener();
v2.setOnTouchListener(v2t);
v1.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
int action = event.getAction();
switch (action & MotionEvent.ACTION_MASK) {
case MotionEvent.ACTION_DOWN:
// do something
break;
case MotionEvent.ACTION_MOVE:
// do something
//if mouse is in bounds of view2 do this:
//for example view is between x= 20 and x = 50
if((event.getX() < 50) &&(event.getX() > 20) )
v2t.onTouch(v2, event);
break;
}
return false;
}
});
来源:https://stackoverflow.com/questions/13530104/mouse-move-on-two-views-how-to-let-both-of-them-handle-the-action-move-event