我正在尝试从包含pdf的视图中获取触摸坐标。 pdf视图是使用PDFViewer库创建的,如果我尝试覆盖该视图的onTouch函数,则无法与之交互。 我的解决方案是使用textview作为覆盖并从中获取坐标,但是如果我返回True还要获取ACTION_MOVE和ACTION_UP,则会消耗touch事件,并且与PDF视图没有交互。如果我返回False,我可以与pdf进行交互,但是只有ACTION_DOWN会被记录。
这是我的代码:
pdfView = findViewById(R.id.pdfView);
pdfView.fromAsset("Hamster_racing.pdf").load();
final View overlay = findViewById(R.id.overlay);
overlay.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
tX = event.getX();
tY = event.getY();
tZ = event.getPressure();
Date curTime = Calendar.getInstance().getTime();
if(event.getAction() == event.ACTION_DOWN){
String logstr = curTime + "ID:"+ ID +","+"Action_down, " +"X:"+ String.valueOf(tX) + ", Y:" + String.valueOf(tY) + ", Pressure:" + String.valueOf(tZ);
Log.i("inputLog", logstr);
toastThis(logstr);
}
if(event.getAction() == event.ACTION_MOVE){
String logstr = curTime + "ID:"+ ID +","+"Action_move, " +"X:"+ String.valueOf(tX) + ", Y:" + String.valueOf(tY) + ", Pressure:" + String.valueOf(tZ);
Log.i("inputLog", logstr);
toastThis(logstr);
}
if(event.getAction() == event.ACTION_UP){
String logstr = curTime + "ID:"+ ID +","+"Action_up, " +"X:"+ String.valueOf(tX) + ", Y:" + String.valueOf(tY) + ", Pressure:" + String.valueOf(tZ);
Log.i("inputLog", logstr);
toastThis(logstr);
}
MotionEvent eventToPass = event;
return true;
}
});
}
有什么方法可以将MotionEvent传递给另一个视图而不消耗它,并获得所有ACTION事件?