In Ordnung, ich werde versuchen, hier mehr Informationen als in meinem ersten Kommentar zu setzen. Also zunächst einmal ist das System nicht annehmen, dieses Verhalten zu ermöglichen, wie in diesem Thread diskutiert: https://groups.google.com/forum/#!topic/android-platform/d6Kt1DhCAtw
aber sagen, dass ich auf diese Fragen kam, als bereit UI Tests auf meine Anwendungen zu automatisieren, insbesondere für die Manipulation Bild , wo ich Finger auf dem Bildschirm simulieren wollte.
Hier ist ein Ausschnitt, die Sie möglicherweise auf Ihre Activity B
anwenden könnte:
Schritt 1: Pass X
und Y
Koordinaten der letzten MotionEvent
Activity A
-Activity B
Schritt 2: Rufen Sie diese Werte in Activity B
und Dann gilt:
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);
}
Können Sie nicht die letzten MotionEvent Informationen von A nach B übergeben und dann ein 'simulieren ACTION_DOWN' sobald B gestartet wurde? – NSimon
@NicolasSimon Ich denke, es ist die richtige Richtung und ich habe es erforscht, bisher erfolglos. – EyesClear
Siehe meine Antwort unter – NSimon