I have an ImageView that I want to change on the Y axis when the user touches and moves. I can move it, but when I move it, it flickers and is not smooth. It also does not follow my finger. Is there a way to remove flicker and improve positioning? I use the standard ImageView.
Here is what I have in the OnTouch method:
imageView.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { switch (event.getAction()){ case MotionEvent.ACTION_DOWN: { final float y = event.getY(); // Remember where we started mLastTouchY = y; } break; case MotionEvent.ACTION_MOVE: final float y = event.getY(); // Calculate the distance moved final float dy = y - mLastTouchY; // Move the object mPosY += dy; // Remember this touch position for the next move event mLastTouchY = y; imageView.setTranslationY(mPosY); return true; } return false; } });
user3925833
source share