ViewFlipper 通过手势切换 ListViews
我有一个以 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
唔。我曾经有一个带有单个列表视图的活动,其中我通过快速手势重新填充了适配器。我通过实现活动的dispatchTouchEvent方法来做到这一点:
列表视图仍然接收正常事件,但我的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:
The listview still received the normal events, but my gestureDectector got to taste them too. Perhaps a similar approach will work for you?
正如 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.