ImageView Overlay Drag and Drop in Android

I have a table-style board game consisting of 10x10 squares. Each square is a PNG image. At the top of these squares, I want to place tiles that can be dragged and packed on top of the squares.

What will be my best approach to Views?

Is it possible to have two layers where the first layer is an ImageView grid that represents the board. Is it possible to allow the slab to be an ImageView that can be “stacked” on top of the ImageView that represents the board?

Any good design ideas are welcome!

Thank.

/ Henrik

+3
source share
2 answers

onTouchEvent :

@Override
public boolean onTouchEvent(MotionEvent event) {
    super.onTouchEvent(event);

    if (!mEnable) {
        return false;
    }

    int action = event.getAction();
    int x = (int)event.getX();
    int y = (int)event.getY();

    switch (action) {
    case MotionEvent.ACTION_DOWN:
        onTouchActionDown(x, y);
        break;
    case MotionEvent.ACTION_MOVE:
        onTouchActionMove(x, y);
        break;
    case MotionEvent.ACTION_UP:
        onTouchActionUp(x, y);
        break;
    }

    return true;
}

onTouchActionUp/Down , .. invalidate() .

onDraw, :

@Override
protected void onDraw(Canvas canvas)
   drawMyDragGfx();
}
+3

onDraw onTouchEvent . .

: -)

+2

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


All Articles