ViewFlipper 通过手势切换 ListViews

发布于 2024-10-25 05:28:17 字数 346 浏览 5 评论 0原文

我有一个以 ListViews 作为子项的 FiewFlipper 。我寻找了一种方法,可以在 GestureDetector 到达子级之前拦截它们 - 一种通过 ViewFlipper 全局拦截触摸事件的方法。

扩展 FiewFlipper 并实现 onInterceptTouchEvent (MotionEvent ev) 似乎是解决方案。这对大多数孩子来说效果很好。但是,当列表视图开始滚动时,onInterceptTouchEvent 停止接收事件。

我知道可以设置每个列表视图的 OnTouchListener,但这会破坏我尝试创建的简单层次结构。

I have a FiewFlipper that has ListViews as children. I have looked for a way to intercept touch events for a GestureDetector before they reach the children - a method to globally intercept touch events over the ViewFlipper.

Extending FiewFlipper and implementing onInterceptTouchEvent (MotionEvent ev) seemed to be the solution. This works well for most children. However, when the listview begins to scroll, onInterceptTouchEvent stop receiving the events.

I know it's possible to set each listview's OnTouchListener, but this ruins simple hierarchy I'm attempting to create.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

携君以终年 2024-11-01 05:28:17

唔。我曾经有一个带有单个列表视图的活动,其中我通过快速手势重新填充了适配器。我通过实现活动的dispatchTouchEvent方法来做到这一点:

@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
    super.dispatchTouchEvent(ev);
    return gestureDetector.onTouchEvent(ev);
}

列表视图仍然接收正常事件,但我的gestureDetector也必须品尝它们。也许类似的方法对您有用?

Hmm. I once had an activity with a single listview, where I re-populated the adapter as a result of fling gestures. I did it by implementing the dispatchTouchEvent method of the activity:

@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
    super.dispatchTouchEvent(ev);
    return gestureDetector.onTouchEvent(ev);
}

The listview still received the normal events, but my gestureDectector got to taste them too. Perhaps a similar approach will work for you?

爱人如己 2024-11-01 05:28:17

正如 adamp 所评论的,这种行为是故意的,不需要反抗。我将手势侦听器应用于子元素。

As commented by adamp, this behaviour is intentional and does not need to be fought. I applied the gesture listener to the children elements.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文