在两种观点的鼠标移动,如何让他们两个处理`ACTION_MOVE`事件 [英] Mouse move on two views, how to let both of them handle the `ACTION_MOVE` event

查看:126
本文介绍了在两种观点的鼠标移动,如何让他们两个处理`ACTION_MOVE`事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个视图,该更大的一个是在底部,而较小的一个是在顶部。显示在下面的图片:

I have two views, the bigger one is on the bottom, and the smaller one is on the top. Show on following picture:

现在我的厂景preSS鼠标(外视图2),然后移动到视图2。我发现即使鼠标是内部视图2在运动过程中,视图2不会得到 ACTION_MOVE 事件。只有厂景能得到它。

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.

我想:

在鼠标内部的厂景,外视图2,让厂景处理 ACTION_MOVE 事件。如果鼠标移动到视图2,然后让视图2处理 ACTION_MOVE 事件。

When the mouse is inside view1 and outside view2, let view1 handle the ACTION_MOVE event. If the mouse move into view2, then let view2 handle the ACTION_MOVE event.

怎么办呢?

PS:Android版本2.X

PS: android version is 2.x

推荐答案

这是不可能的,但你可以做一些事情其他人:

It is not possible,but you can do some things else:

获取鼠标和视图2坐标,如果鼠标在视图2的范围,直接试试你want.Or,如果你愿意,你可以叫 view2.onTouch 的方法,创建一个touchlistener类V2,例如 V2TouchListener 则:

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;
    }
});

这篇关于在两种观点的鼠标移动,如何让他们两个处理`ACTION_MOVE`事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆