TextView的内部ViewPager截获触摸事件 [英] TextView inside ViewPager intercepts touch events

查看:318
本文介绍了TextView的内部ViewPager截获触摸事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 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.

祝你好运!

这篇关于TextView的内部ViewPager截获触摸事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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