将触摸事件发送到同级视图

编程入门 行业动态 更新时间:2024-10-28 06:21:24
本文介绍了将触摸事件发送到同级视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我开发了一个扩展 ViewGroup 的自定义布局.现在,我想在活动中使用它.在我的活动中,我在框架布局中同时拥有这个布局和一个viewpager.我的自定义布局填充了我的 Frame 布局并且位于我的 viewPager 之上.

I have developped a custom layout that extends ViewGroup. Now, I want to use it in an activity. In my activity, I have both this layout and a viewpager inside a framelayout. My custom layout fills my Frame layout and is above my viewPager.

我希望能够在我的自定义布局上处理点击事件,并让所有其他动作转到 viewpager,以便它仍然可以滚动.

I would like to be able to handle click events on my custom layout and let all the other motions go to the viewpager so it can still scroll.

到目前为止我还没有做到.要么我有点击,但 viewpager 不能再滚动,或者相反.我已经覆盖了 onTouchEvent 和 onInterceptTouchEvent.

I haven't managed so far. Either I have the click but the viewpager cannot scroll anymore, or the contrary. I have overriden onTouchEvent and onInterceptTouchEvent.

我注意到的是,我在我的自定义布局上正确地收到了 down 事件,但是一旦它被 viewpager 捕获,我就永远不会到达那里.如何在触摸事件的兄弟视图之间进行通信?

What I notice is that, I correctly receive the down event on my custom layout, but once it has been catched by the viewpager, I do never get up there. How can I make communications between sibling views for touch events ?

PS:我试过 splitMotionEvent 无济于事

PS : I have tried splitMotionEvent to no avail

推荐答案

确保您的自定义布局的 onTouchEventdispatchTouchEvent 处返回 trueACTION_DOWN 发生,然后您的自定义布局将在稍后收到 ACTION_MOVEACTION_UP.

make sure either the onTouchEvent or the dispatchTouchEvent of your custom layout returns true at the ACTION_DOWN happens, and then your custom layout will recieve the ACTION_MOVE and ACTION_UP later.

这篇关于将触摸事件发送到同级视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-04-30 02:21:29,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1388256.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:发送到   视图   事件

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!