我如何让一个触摸事件保持其焦点在它开始的小部件上?[英] How do I keep a touch event keep its focus on the widget it was started in?

本文是小编为大家收集整理的关于我如何让一个触摸事件保持其焦点在它开始的小部件上?的处理/解决方法,可以参考本文帮助大家快速定位并解决问题,中文翻译不准确的可切换到English标签页查看源文。

问题描述

让我们说我有一个listview,它是一个行是我的自定义视图.用户触摸自定义视图中 - >自定义视图获取此触摸事件.用户继续在自定义视图中的此触摸序列 - >自定义视图也可以处理这些事件.

问题:当用户将他/她的手指拖动到自定义视图的区域外(拖动内部)外,自定义视图丢失了触摸事件.但我也需要这些活动,我该如何实现这一目标?

我知道这可以做到这一点:如果您在lisview中放置了一个包含一堆图像的图库,我开始拖动左右拖动画廊,然后在画廊的区域外拖动我的手指(向上/向下移动太多),我仍然控制画廊滚动,而不是ListView.

我希望我足够清楚,有没有人对这个问题有一些提示?

推荐答案

根据这个帖子通过Dianne Hackbank,如果在视图的onTouchEvent()中返回到下降事件,则会自动向该视图发送以下事件.

本文地址:https://www.itbaoku.cn/post/102429.html

问题描述

Let's say I have a ListView, and one row in it is a custom View of mine. The user touches inside the custom view -> custom View gets to handle this touch event. User continues this touch sequence inside the are of the custom View -> custom View gets to handle those events too.

Problem: When the user drags his/her finger outside the area of the custom View (the drag started inside), the custom View losts the touch events. But I need those events too, how can I achieve this?

I know that this can be done: if you put a Gallery containing a bunch of images inside a LisView, and I start to drag the Gallery left-right, and drag my finger outside the area of the Gallery while doing so (moving up/downwards too much), I still control the Gallery scrolling, not the ListView.

I hope that I was clear enough, does anyone have some tips on this problem?

推荐答案

According to this post by Dianne Hackborn, if you return true to a down event in a view's onTouchEvent(), following events are sent automatically to that view.