使用TextView作为内容处理自定义容器中的onTouch事件

时间:2015-02-22 19:34:08

标签: android android-layout textview ontouchevent

我有以下问题。

在Android应用程序中,有一个自定义布局类,它扩展了FrameLayout。它会覆盖onTouchEvent方法以实现自定义实现。我们有一个TextView,它作为此布局类的内容。我们希望此TextView中的URL链接可以单击。为此,我们将“android:autoLink =”web“'添加到TextView的属性中。接下来是Xml:

            <PinchZoomScrollView
                  android:layout_weight="350"
                  android:layout_width="0dp"
                  android:layout_height="match_parent"
                  android:id="@+id/newsDetailScrollView">

                <TextView 
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:autoLink="web"
                    android:id="@+id/newsDetailText"/>

            </PinchZoomScrollView>

添加autoLink =“web”后,似乎没有调用自定义布局类“PinchZoomEvent”的onTouchEvent。具有autoLink属性的TextView似乎以某种方式阻止触摸事件。这很奇怪,因为PinchZoomScrollView是TextView的父级,它应该首先接收事件。在这种情况下该怎么办?

1 个答案:

答案 0 :(得分:1)

家长不会在Android中自动接收触控内容。您正在考虑其他框架。触摸事件从孩子开始,然后在Android中上传。如果您有一个父类(如滚动器)想要拦截触摸事件并可能覆盖子行为,则需要实现onInterceptTouchEvent,并在检测到要从子项中执行的操作时从中返回true。

相关问题