问题描述
我开发了一个扩展 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
推荐答案
确保您的自定义布局的 onTouchEvent
或 dispatchTouchEvent
在 处返回 trueACTION_DOWN
发生,然后您的自定义布局将在稍后收到 ACTION_MOVE
和 ACTION_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.
这篇关于将触摸事件发送到同级视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!