问题描述
我有一个自定义的 ViewSwitcher
中,我实现了触摸事件,所以我我能够通过屏幕使用触摸屏滚动。
I have a custom ViewSwitcher
in which I implemented touch events so Iam 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 theListViews
and I am not able to switch the views. It works fine when Idon't have the ListViews
. I need to be able to scroll through theviews 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.
这篇关于传递触摸事件父视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!