Skip to content Skip to sidebar Skip to footer

Trying To Understand Ontouch Method

I have an image and it moves to my finger position when I touch it, Everything is working but I want to know what these variables do. Part of code //I'm trying since the morning to

Solution 1:

dX and dY is a difference between top left corner of this view and touch point on this view - you are touching view somewhere in the middle of it, almost never on its edge (pixel on 0,0 coordinates). when ACTION_MOVE occurs then you are using setX/setY methods for changing position, which are setting position of this top left corner - for preserving feeling of dragging (no view jump, smooth drag) you have to add these initial difference. use Log.i(..) and observe Logcat tab in Android Studio, you will notice which value is responsible for which param of touch/view


Post a Comment for "Trying To Understand Ontouch Method"