传输触控对焦另一种观点 [英] Transferring touch focus to another view

查看:109
本文介绍了传输触控对焦另一种观点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这问题有点尴尬。是否有可能以一个视图的触控对焦转移到另一个?基本上,说,你有拿起第一个 ACTION_DOWN 触摸事件,然后马上想给所有的触摸事件转移焦点,以另一种观点来处理与它的<视图code> onTouchEvent(MotionEvent事件)。我认为,执行以下操作将使其工作,但事与愿违:

This question is a bit awkward. Is it possible to transfer the touch focus of one view to another? Basically, say that you have a view that picks up the first ACTION_DOWN touch event, and then immediately wants to transfer the focus for all touch events to another view to handle with it's onTouchEvent(MotionEvent event). I thought that doing the following would make it work, but it didn't:

 @override
 public boolean onTouchEvent(MotionEvent) {
      this.clearFocus();
      anotherView.setFocusableInTouchMode(true);
      anotherView.requestFocus();
 }

显然,在我看来,它只是不这样的。可能有人向我解释,我怎么能去这样做这样的事情?

Obviously, it seems to me that it just doesn't work that way. Could someone explain to me how I can go about doing something like this?

如果它仍然是一个有点难以明白我的问题,想想一个普通按钮。当pressed,突出显示该按钮(聚焦),如果你移动你的手指离开按钮,但仍保持你的手指在屏幕上,该按钮会变为聚焦,但仍然拥有全触摸事件的控制(没有其他视图可以成为重点即使你动过它们)。我的问题是问,如果有可能,而无需您删除你的手指在屏幕这个触控对焦转移到另一种观点来处理。

If it's still a bit difficult to understand my question, think about a regular button. When pressed, the button is highlighted (focused) and if you move your finger off the button but still keep your finger on the screen, the button becomes unfocused but still has control of the entire touch events (no other view can become focused even if you move over them). My question asks if it is possible to transfer this touch focus to another view to handle without having you to remove your finger off the screen.

推荐答案

尝试下面code可能会奏效

Try below code might work

button1.setOnFocusChangeListener(new OnFocusChangeListener()
{           
    @Override
    public void onFocusChange(View arg0, boolean hasFocus)
    {
        if(hasFocus)                
            button2.requestFocus();             
    }
});

这篇关于传输触控对焦另一种观点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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