各位有没有用过Instrumentation这个类,测试的朋友可能用过,用来发送坐标和按键等事件用的。
现在有个问题,我在自己的一个全屏的popupwindow窗口中,想要在点击事件时隐藏掉自己的全屏窗口,然后发送这个点击的事件给全屏窗口后面的控件去接收。类似一种穿透的效果。
Instrumentation这个类提供了touch的发送模拟
// Instrumentation inst=new Instrumentation();
// inst.sendPointerSync(MotionEvent.obtain(SystemClock.uptimeMillis(),
// SystemClock.uptimeMillis(),
// MotionEvent.ACTION_DOWN, mTouchX, mTouchY, 0));
// inst.sendPointerSync(MotionEvent.obtain(SystemClock.uptimeMillis(),
// SystemClock.uptimeMillis(),
// MotionEvent.ACTION_UP, mTouchX, mTouchY, 0));
具体使用方法:
http://blog.csdn.net/roger_ge/archive/2010/05/03/5551812.aspx
主要是UI线程中不可以直接使用Instrumentation的方法,不然会挂掉。
只能放在子线程中处理,现在目前事件发送了,但是好像全屏窗口后面并没有收到这个事件。
不知道大家有没有做过这方面的,分享下,谢谢~