传递触摸事件父视图 [英] Passing touch events to the parent view

查看:106
本文介绍了传递触摸事件父视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个自定义的 ViewSwitcher 中,我实现了触摸事件,所以我 我能够通过屏幕使用触摸屏滚动。

I have a custom ViewSwitcher in which I implemented touch events so I am able to scroll through screens using the touchscreen.

我的布局层次结构是这样的:

My layout hierarchy looks like this:

<ViewSwitcher>

    <LinearLayout>
        <ListView />
    </LinearLayout>

    <LinearLayout>
        <ListView />
    </LinearLayout>

</ViewSwitcher>

现在,问题是,在触摸事件被消耗的 列表视图,我不能够切换的意见。它工作正常,当我 没有列表视图。我需要能够以滚动 意见和滚动的ListView

Now, the problem is that the touch events are being consumed by the ListViews and I am not able to switch the views. It works fine when I don't have the ListViews. I need to be able to scroll through the views and scroll the ListView.

我要如何解决这个问题?

How do I solve this?

修改:我还需要的ListView 项目可以点击

EDIT: I also need the ListView items to be clickable.

在此先感谢!

推荐答案

谢谢大家的回答这个问题。但我能理解它在一个更简单的方式。由于我的 ViewSwitcher 未检测到触摸事件,我截取了触摸事件,被称为的onTouchEvent()返回。这里:

Thank you everyone for answering the question. But I was able to figure it out in a much simpler manner. Since my ViewSwitcher wasn't detecting the touch event, I intercepted the touch event, called the onTouchEvent() and returned false. Here:

@Override
public boolean onInterceptTouchEvent(MotionEvent ev)
{
    onTouchEvent(ev);
    return false;
}

通过覆盖 onInterceptTouchEvent(),我能够拦截触摸事件的活动。然后我叫的onTouchEvent() ViewSwitcher 它处理的切换列表视图。最后通过返回,它确保了的ViewGroup 不消耗事件。

By overriding the onInterceptTouchEvent(), I was able to intercept the touch event in the activity. Then I called the onTouchEvent() in the ViewSwitcher which handles the switching of the ListViews. And finally by returning false, it makes sure that the ViewGroup doesn't consume the event.

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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆