Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/211.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 关于几个观点的讨论_Android - Fatal编程技术网

Android 关于几个观点的讨论

Android 关于几个观点的讨论,android,Android,我的问题是,我想尝试接收任何触摸屏上的任何地方。 为此,我想的是创建一个带有主“RelativeLayout”的布局。该活动实现“onTouchListener”。这是我的布局: <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/relative" xmlns:tools="http://schemas.android.com/tools" android:

我的问题是,我想尝试接收任何触摸屏上的任何地方。 为此,我想的是创建一个带有主“RelativeLayout”的布局。该活动实现“onTouchListener”。这是我的布局:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/relative"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >

<ImageView
    android:id="@+id/imageView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true"
    android:layout_centerVertical="true"
    android:src="@drawable/ic_launcher" /></RelativeLayout>
关键是,如果我触摸图像,它不会显示吐司(如果你触摸屏幕上的任何位置,我想显示吐司)

任何人都知道我如何接收活动中触摸屏幕的事件(无论在哪里??)

编辑:我想要的不是ImageView的监听器,我想要的是知道是否有方法接收用户触摸屏幕的事件


非常感谢

尝试将触控监听器添加到图像中,而不是添加到主相对布局中

imagen.setOnTouchListener(this);

由于您的ImageView是可单击的,因此触摸事件将被发送到ImageView,活动无法接收它。 如果要在发送到查看之前拦截所有触摸事件,应覆盖
活动。dispatchTouchEvent(MotionEvent ev)


不是解决方案,因为这是一个示例,但我想要的是尝试在视图上添加许多对象,并且无论如何尝试获取用户触摸屏幕本身的事件,而不是对象本身…谢谢!!这正是我想要的!!
imagen.setOnTouchListener(this);
public boolean dispatchTouchEvent(MotionEvent ev) {
    // add your code here
    return super.dispatchTouchEvent(ev);
}