继续从一个活动滚动到另一个活动
问题描述:
我有两项活动:ActivityA
& ActivityB
。 ActivityA
正在侦听运动事件。滚动事件发生时,立即启动ActivityB
。继续从一个活动滚动到另一个活动
ActivityB
里面有一个可滚动的内容,我希望它立即开始滚动此内容,而不会强迫用户举起手指。过渡必须是透明的,滚动手势不应该停止在活动之间,而是顺利地继续。
换句话说,问题在于ActivityB
对运动事件没有反应,除非用户抬起手指并再次触摸屏幕。
我该如何解决这个问题?
答
好的,我会尽量在这里提供比我第一次评论更多的信息。 所以首先,系统不应该允许这种行为,因为在该线程讨论:https://groups.google.com/forum/#!topic/android-platform/d6Kt1DhCAtw
话虽这么说,我碰到这个问题时,愿意在我的应用程序会自动UI测试来了,尤其是对于图像处理,我想在屏幕上模拟手指。
这里,你可能会应用到您的Activity B
一个片段:
第1步:通过从Activity A
最后MotionEvent
的X
和Y
坐标Activity B
步骤2:Activity B
检索这些值,并然后应用:
private void continueScrolling(int posX, int posY) {
long downTime = SystemClock.uptimeMillis();
long eventTime = SystemClock.uptimeMillis();
MotionEvent.PointerCoords[] pointerCoords = new MotionEvent.PointerCoords[1];
MotionEvent.PointerCoords pc1 = new MotionEvent.PointerCoords();
pc1.x = posX;
pc1.y = posY;
pc1.pressure = 1;
pc1.size = 1;
pointerCoords[0] = pc1;
MotionEvent.PointerProperties[] pointerProperties = new MotionEvent.PointerProperties[1];
MotionEvent.PointerProperties pp1 = new MotionEvent.PointerProperties();
pp1.id = 0;
pp1.toolType = MotionEvent.TOOL_TYPE_FINGER;
pointerProperties[0] = pp1;
MotionEvent event;
// send the initial touches (this seems to be to "wake up" the view, you might not need it in a non-testing context though)
event = MotionEvent.obtain(downTime, eventTime,
MotionEvent.ACTION_DOWN, 1, pointerProperties, pointerCoords,
0, 0, // metaState, buttonState
1, // x precision
1, // y precision
0, 0, // deviceId, edgeFlags
InputDevice.SOURCE_TOUCHSCREEN, 0); // source, flags
theViewYouWantTomove.dispatchGenericMotionEvent(event);
event = MotionEvent.obtain(downTime, eventTime,
MotionEvent.ACTION_DOWN,
1, pointerProperties, pointerCoords, 0, 0, 1, 1, 0, 0,
InputDevice.SOURCE_TOUCHSCREEN, 0);
theViewYouWantTomove.dispatchGenericMotionEvent(event);
}
您不能将最后一个MotionEvent信息从A传递给B,然后模拟一个'一旦B启动,ACTION_DOWN'? – NSimon
@NicolasSimon我认为这是正确的方向,我一直在探索它,迄今为止没有成功。 – EyesClear
看到我的回答下面 – NSimon