Raziza O
Raziza O

Reputation: 1646

Transforming path and redrawing does not work

I have Path that I'm creating once, and adding Rect to it.

On some event I'm offsetting the path by Path.offset(...) or Path.transform(...) and then invalidating my canvas for redrawing the path.

But the path is not redrawing in the new place.

I checked the path bounds by using Path.computeBounds(...) and I see that the rectangle moved. So I don't understand why Canvas.drawPath(...) is not redrawing the path in the new place.

The only way I managed to make the path redrawn in the new place is to make new path and add the transformed path to it, but I don't really want to do it every time.

m_objPath.offset(p_fltDx, p_fltDy);

//////////////////////////////  
// With this lines it makes the path redrawn in the right place - but why should i ??
Path objPath = new Path();
objPath.addPath(m_objPath);
m_objPath = objPath;
//////////////////////////////

m_objCanvas.invalidate();
.
.
.

m_objCanvas.drawPath(m_objPath, m_objPaint);

Any suggestions?

Upvotes: 2

Views: 599

Answers (1)

sberezin
sberezin

Reputation: 3296

I tested the issue with Path.offset(..) against Android 4.1 and Android 2.3:

  • On Android 2.3 offset(..) works ok.
  • On Android 4.1 it fails to show new position of the path. Still it is moved! If I return to main screen (central hardware button on my Samsung) and start app again - it shows correct position.

So just drop using Path...

Upvotes: 1

Related Questions