TextView的内部ViewPager截获触摸事件事件、TextView、ViewPager

2023-09-04 11:34:24 作者:饮晚风.

我有一个 ViewPager 包含两个片段。在任一片段我可以触摸的地方,滑动切换到另一个片段。一个片段包含一个列表。在列表中的项目包含一个的TextView 和一个的ImageView 。是,如果你拖着已经启动的问题,从敲击的ImageView ,它的确定。但是,如果它已经从的TextView ,拖动从未知道的 ViewPager ,其结果是平滑切换从未发生过。

I have a ViewPager that contains two fragments. In any of the fragments I can touch a place, swipe to switch to another fragment. One of the fragments contains a list. Items in the list contains one TextView and one ImageView. The issue is, if you dragging has been started from tapping the ImageView, it's OK. But if it's been from the TextView, the drag was never known to the ViewPager, as a result the 'smooth switching' never happens.

在这个任何线索?

修改

这画面是展示如何我的GUI是。如果拖拽已启动从TextViewE,它不会开始。

This picture is to show how my GUI is. If the drag has been started from TextViewE, it doesn't begin.

推荐答案

这件事困扰我太多,但我已经成功地找到了答案。

This thing bothered me too, but I've managed to find the answer.

基本上的情况是:如果视图可以水平滚动,它拦截的水平运动赛事和 ViewPager 无法再处理它

Basically, the case is: if the view can scroll horizontally, it intercepts the horizontal motion event and ViewPager is not able to process it anymore.

由于 API级别14 TextViews有机器人:scrollHorizo​​ntally 属性(和 setHorizo​​ntallyScrolling(布尔)方式),如果设置为true,导致TextView的拦截水平滚动移动事件。

Since API Level 14 TextViews have android:scrollHorizontally property (and setHorizontallyScrolling(boolean) method), which, if set to true, causes the TextView to intercept horizontal scroll motion events.

您可以将其设置为false,无论是在XML或就在code,但注意的机器人:单线属性力量机器人:scrollHorizo​​ntally 被设置为真正! 非常棘手的问题的!但幸运的是,你通常能够安全地替换单行财产机器人:MAXLINES =1和必要的 ellipsize 值

You may set it to false either in XML or right in the code, but watch out: android:singleLine property forces android:scrollHorizontally to be set to true! Very tricky point! But fortunately, you usually able to safely replace single line property with android:maxLines="1" and necessary ellipsize value.

祝你好运!