You could do something like this (example):
int howLongUntilEdge = 1000;
CountDownTimer t = new CountDownTimer(howLongUntilEdge, 1000) {
@Override
public void onTick(long millisUntilFinished) {
myobject.setX(myobject.getX() - 10);
}
@Override
public void onFinish() {}
};
then on your touch event:
@Override
public boolean onTouchEvent(MotionEvent event) {
synchronized (getHolder()) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
t.start();
} else if (event.getAction() == MotionEvent.ACTION_UP) {
t.stop();
}
return true;
}
}
It would move it left by 10 every second. You would need to do something like decide how many seconds until it would reach the edge and set the howLongUntilEdge
var to reflect the correct value