[android] android: move a view on touch move (ACTION_MOVE)

I'd like to do a simple control: a container with a view inside. If I touch the container and I move the finger, I want to move the view to follow my finger.

What kind of container (layout) should I use? How to do this?

I don't need to use a surface, but a simple layout.

This question is related to android touch

The answer is

I've found an easy approach to do that with the ViewPropertyAnimator:

float dX, dY;

public boolean onTouch(View view, MotionEvent event) {

    switch (event.getAction()) {

        case MotionEvent.ACTION_DOWN:

            dX = view.getX() - event.getRawX();
            dY = view.getY() - event.getRawY();

        case MotionEvent.ACTION_MOVE:

                    .x(event.getRawX() + dX)
                    .y(event.getRawY() + dY)
            return false;
    return true;

Similar questions with android tag:

Similar questions with touch tag: