简体   繁体   English

GLSurfaceView OnTouchEvent从未调用

[英]GLSurfaceView OnTouchEvent never called

In my Xamarin Android application I created an Activity with custom GLSurfaceView on it. 在我的Xamarin Android应用程序中,我创建了一个带有自定义GLSurfaceView的Activity。 The layout is following: 布局如下:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:local="http://schemas.android.com/apk/res-auto"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textSize="20dp"
        android:text="Hi! I am model viewer!" />
    <test.ui.droid.controls.ModelViewerGLSurfaceView
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1" />
</LinearLayout>

My custom ModelViewerGLSurfaceView (derived from GLSurfaceView) is needed for OpenGL rendering and works just fine. 我的自定义ModelViewerGLSurfaceView (从GLSurfaceView派生)是需要OpenGL渲染和工作得很好。

Now I want to add gesture recognition. 现在,我想添加手势识别。 In order to do that I overridden OnTouchEvent in my ModelViewerGLSurfaceView, but this function is never called, no matter what I do. 为了做到这一点,我在ModelViewerGLSurfaceView中重写了OnTouchEvent,但是无论我做什么,都永远不会调用此函数。

However when I override OnTouchEvent on parent Activity, it works. 但是,当我在父Activity上覆盖OnTouchEvent时,它将起作用。

Why OnTouchEvent is never called for my GLSurfaceView? 为什么从不为我的GLSurfaceView调用OnTouchEvent?

Did you by any chance forget to register the onTouchListener? 您是否偶然忘记注册onTouchListener?

You need to call setOnTouchListener on your view to register the callback. 您需要在视图上调用setOnTouchListener来注册回调。

http://developer.android.com/reference/android/view/View.html#setOnTouchListener(android.view.View.OnTouchListener) http://developer.android.com/reference/android/view/View.html#setOnTouchListener(android.view.View.OnTouchListener)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM