Android Question

onDrag not called when not moving finger

I'm creating an Android app with drag and drop support inside a zoomed image. I need to pan the image when the user moves the finger close to the edge of the screen. I check this if the event's action is ACTION_DRAG_LOCATION.

The problem I'm facing is that the onDrag() method in my onDragListener does not get called when the user's finger reaches the edge of the screen and stops moving.

I tried overriding the onTouch() method of my Activity but the events are not getting trigger when dragging.

Does someone know a way to achieve this?
Thanks in advance.

Answer Source

I ended up creating a Runnable that I start in the onDrag Method:


private Runnable runnable = new Runnable() {
    public void run() {
        long millis = SystemClock.uptimeMillis();
        if (insideOfMe) {
            int[] locations = new int[2];
            int x = locations[0];
            int y = locations[1];
            float speed = 10;
            if (dragEvent.getX() - speed < x) {
                pinView.panTheImage(speed, 0);
            if (dragEvent.getX() + speed > x + mapAreaLayout.getWidth()) {
                pinView.panTheImage(-speed, 0);
            if (dragEvent.getY() - speed < y) {
                pinView.panTheImage(0, speed);
            if (dragEvent.getY() + speed > y + mapAreaLayout.getHeight()) {
                pinView.panTheImage(0, -speed);


        handler.postAtTime(this, millis + 16);


if (event.getAction() == DragEvent.ACTION_DRAG_STARTED) {

And then I remove the callback to the Runnable:

if (event.getAction() == DragEvent.ACTION_DRAG_ENDED) {
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download