Animate / drag an object in Android

I have a custom view (extends View) that will be a game board. Now I would like to create an object (well, a bunch of them, but I can start with it) in a specific place on the board, and then the user will be able to move it by dragging it. I have a look of the board down, but I'm at a loss on how to code the "pieces". Thank you for any help and / or pointing to the right place here.

+4
source share
1 answer

Some pointers:

  • You will need to capture the press of the "n" button. Unfortunately, you cannot use the GestureDetector.SimpleOnGestureListener for this (it will treat it as a scroll), so you will need to do this in your onTouchEvent view. It's a little tricky - check out the SimpleOnGestureListener source code for ideas on how best to do this.
  • When you update the call location of an invalidate () object in a view to trigger a re-draw
  • In onDraw (), make a background image and then draw your object on top

If you just make one object at a time, that should be enough. If you like it better, you may have to end up with SurfaceView and a separate stream, but don't get there until you need it.

+1
source

Source: https://habr.com/ru/post/1314195/


All Articles