我想知道是否有可能通過GLSurfaceView獲取ImageView並獲取兩者的相應觸摸事件。我的問題是,我想知道何時按下ImageView(因此我會使用OnTouchListener)。但是,我仍然希望能夠獲得我的GLSurfaceView的touchEvents。觸摸事件ImageView + GLSurfaceView
我曾嘗試是從我的GLSurfaceView刪除的onTouchEvent的實施,使類實現OnTouchListener並實現onTouchsuch爲:
公共布爾onTouch(視圖V,MotionEvent事件){ INT行動=事件。的getAction();
if(v.getId() == R.id.ImageView ;){
switch (action) {
case MotionEvent.ACTION_DOWN:
//Do something
break ;
//....
}
}
else{
//Process GLSurfaceView touch events
}
}
當我這樣做的問題是,我不能結合撫摸我的ImageView和撫摸我的GLSurfaceView這是我真正想要達到的。因此,我嘗試添加一個檢查手指的數量,但仍然無法使其工作,因爲當我同時觸摸ImageView和GLSurfaceView時只檢測到一個手指。 現在,很難解釋,但是當我將一個手指放在imageView和另一個手指放在我的GLSurfaceView的其他位置時,不知何故我的一部分代碼在調用時,手指位置在ImageView上,而不是其他手指。
一個用例的例子是:想象一下,我在拿着平板電腦時使用我的兩隻手。如果我用左手拇指按下這個ImageView,我想從我的右拇指在屏幕上進行手指移動來執行旋轉,而不是翻譯或類似的東西。
所以,我想知道到目前爲止我的實現有什麼問題。也許我沒有正確地考慮這個問題。在這種情況下,我很樂意知道什麼是錯的,以及如何正確地實現這種事情。
由於提前,
編輯: 這是我activity_main.xml中
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:id= "@+id/linearlayout1" >
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="450dp"
android:id= "@+id/relativeLayout" >
<com.kitware.VolumeRender.VolumeRenderView
android:id="@+id/glSurfaceViewID"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="0.23" />
<ImageView
android:id="@+id/ImageView"
android:layout_width="60dp"
android:layout_height="70dp"
android:layout_alignParentLeft="true"
android:layout_centerInParent="true"
android:src="@drawable/i3" />
<ImageView
android:id="@+id/ImageView2"
android:layout_width="40dp"
android:layout_height="match_parent"
android:layout_alignParentRight="true"
android:src="@drawable/tmp" />
</RelativeLayout>
<Spinner
android:id="@+id/myspinner"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:entries="@array/country_arrays"
android:prompt="@string/country_prompt" />
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:id= "@+id/linearlayout2" >
// And so on, the end of the file is irrelevant I suppose
是這兩個視圖的視圖邊界是否一樣?還有哪些是最重要的? – Bhargav
@Bhargav不太明白你的第一個問題。 ImageView處於頂端。即將編輯添加我的activity_main.xml內容 – LBes
意思是ImageView完全覆蓋了表面視圖?如果這樣你的surfaceView永遠無法獲得焦點 – Bhargav