我在 Android 中有一个 SurfaceView
“覆盖”一个 GLSurfaceView
。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<my.project.ActionSurface
android:id="@+id/actionSurface"
android:layout_marginBottom="30dip"
android:layout_marginLeft="20dip"
android:layout_marginRight="20dip"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
/>
<fi.harism.curl.CurlView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/larryMoeCurly"
/>
</RelativeLayout>
(非常感谢 harism 提供他的 page curl 代码!)
在我的 ActionSurface 中,我有这个来检测触摸:
public boolean onTouchEvent(MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
newX = (int) event.getX();
newY = (int) event.getY();
diffX = newX - x;
diffY = newY - y;
Log.d(TAG, "touched at x:" + newX + " y:" + newY);
}
return true;
}
当我触摸我的 ActionSurface 时,它会正确响应,但触摸也会传递到 CurlView。如何阻止触摸“穿过”另一个表面?
最佳答案
您可以将 OnTouchListener 添加到表面 View ,并在那里捕获事件(返回 true):
this.setOnTouchListener(new View.OnTouchListener()
{
@Override
public boolean onTouch(View v, MotionEvent event)
{
return true;
}
});
关于android - 阻止触摸传递到下表面 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5815663/