I have a RelativeLayout with a TextView in the middle. I've got it to detect onFling, onDown, and onScroll events using SimpleOnGestureListener().
I would like the TextView to follow my finger around the screen (can be just in the x axis), and when I lift my finger for it so animate either out of the screen or back to the middle (depending on how far I've moved it).
This is what I normally do in these cases.
First of all, your onScroll method should look something like this:
We are modifying the
leftMargin
andtopMargin
an amount equivalent to the distance that has been scrolled.Next, to make the text view animate back to its original position you need to do so when the the event is
ACTION_UP
orACTION_CANCEL
:Then in the snapBack method we animate back the text view:
And that should do! You can modify the
endValueX
andendValueY
variables to control where the text view goes back when you lift your finger.