简体   繁体   English

如果按下起源于该视图之外,如何检测是否正在触摸该视图?

[英]How to detect if a view is being touched if the press down originates outside of that view?

I want to touch down on the view of object B and swipe to ie.我想触及 object B 的视图并滑动到 ie。 object 3 where I release it. object 3 我发布的地方。 It needs to register that is has been released at object 3. I thought to give object 3 a OnTouchListener as well but that ontouchlistener is not called since it started outside of its view.它需要注册已在 object 3 发布的。我想给 object 3 一个 OnTouchListener,但没有调用 ontouchlistener,因为它在其视图之外启动。 I dont think a global ontouchlistener working back to coordinates will work since its all in a ScrollView.我认为返回坐标的全局 ontouchlistener 不会起作用,因为它全部在 ScrollView 中。 I tried several callback but none seem to work and I can't find an answer to this.我尝试了几个回调,但似乎都没有用,我找不到答案。 So, How to detect if a view is being touched if the press down originates outside of that view?那么,如果按下来自该视图之外,如何检测是否正在触摸该视图?

在此处输入图像描述

As @cactustictacs suggested the Drag and Drop works great for this.正如@cactustictacs 所建议的那样,拖放非常适合此操作。 Basically:基本上:

  1. Set a onTouchListener on objects B view that starts a drag action.在启动拖动操作的对象 B 视图上设置 onTouchListener。
  2. Extend DragShadowBuilder and create a custom background/shadow for the dragged object. (Transparent drawable for me)扩展 DragShadowBuilder 并为拖动的 object 创建自定义背景/阴影。(对我来说是透明可绘制对象)
  3. Add data of object B to the drag action拖拽动作添加object B的数据
  4. Set Object 1 2 3 views as drop zones by implementing onDragListeners.通过实现 onDragListeners 将 Object 1 2 3 视图设置为拖放区。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM