我的相对布局中有自定义视图和EditText元素,我无法在自定义视图中接收触摸事件,如何将触摸事件传播到自定义视图;
我的布局看起来像;
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/white" >
<com.test.ui.CustomView
android:id="@+id/noteView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<EditText
android:id="@+id/etPageInput"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="top" />
</RelativeLayout>
我将触摸侦听器添加到我的EditText和Custom视图中;
EditText pageInput = (EditText) findViewById(R.id.etPageInput);
pageInput.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
return false;
}
});
CustomView pageView = (CustomView) findViewById(R.id.noteView);
pageView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
System.out.println("Touch event received by custom view !!!")
return true;
}
});
我无法在自定义视图中接收触摸事件,不知道我缺少什么?
答案 0 :(得分:0)
尝试在自定义视图的xml中将clickable设置为true 和 尝试setonclicklisener