android - 阻止触摸传递到下表面 View

标签 android surfaceview

我在 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/

相关文章:

java - 无法通过电子邮件 Intent 发送电子邮件

android - 将大图设置为 SurfaceView 的背景,使其适合 Android 中的显示高度

android - SurfaceView 的 renderThread 是否应该与 View 或 Activity 具有相同的生命周期?

android - 如何使用 YouTube Android Player API 播放 YouTube 直播?

android - AutoCompleteTextView 下拉列表中的项目不可见。如何改变他们的颜色..?

android - createScaledBitmap 的过滤器参数有什么作用?

android - SurfaceView 的缩放动画

java - Android 从 Socket 读取内容卡在第二个读取循环上

android - 在android中使用没有预览或表面的相机

android - SurfaceView + Canvas,从一种颜色淡入另一种颜色