0

Move rectangle on finger touch event and also Resize rectangle by moving it left ,right, top or bottom line finger touch and rotate it when I touch or move on bottom right corner of the rectangle(show in figure) and redraw it (canvas) android please help if anyone can.

enter image description here

svkaka
  • 3,942
  • 2
  • 31
  • 55
zain
  • 1
  • 3

1 Answers1

0

If you have all in a child class from View you could override

@Override
public boolean onTouchEvent(MotionEvent event) {
    final Point point = new Point((int) event.getX(), (int) event.getY());
    switch (event.getAction()) {
        case MotionEvent.ACTION_DOWN:
            press(point);
            break;
        case MotionEvent.ACTION_MOVE:
            drag(point);
            break;
        case MotionEvent.ACTION_UP:
            release(point);
            break;
    }
    return true;
}

In the method press(Point point) you need to identify with point to point or point to line distance which feature is the most near to be selected. And the method drag(Point point) helps you to drag the rect.

Drawing

Drawing should take place in the onDraw(Canvas canvas) method but the instantiation should be outside this method. So you create the Rect in your constructor or so

Rect rect = new rect(10, 10, 100, 100)

Resize

When you try to resize you don't need to create a new Rect you'll just use

rect.set(x, y, dx, dy)

Rotate

When you want to rotate you need to rotate the Canvas then draw and afterwards rotate back to draw something else.

canvas.save();
canvas.rotate(45);
canvas.drawRect(rect, paint);
canvas.restore();
Peppermint Paddy
  • 1,269
  • 9
  • 14