我想知道是否可以通过GLSurfaceView获得ImageView并获得两者的相应触摸事件。我的问题是我想知道何时按下ImageView(因此我会使用OnTouchListener)。但是,我仍然希望能够获得我的GLSurfaceView的touchEvents。
我尝试过从GLSurfaceView中删除onTouchEvent的实现,并使该类实现OnTouchListener并实现onTouchs,如:
public boolean onTouch(View v,MotionEvent event){ int action = event.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上的其他地方时,不知怎的,我在else部分的代码片段是用手指在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
答案 0 :(得分:0)
You can do something like this
imageView.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
if(hasFocus) {
v.getParent().requestDisallowInterceptTouchEvent(true);
} else {
v.getParent().requestDisallowInterceptTouchEvent(false);
}
}
});
And same with your surfaceView too