转化路径和重绘不起作用路径、不起作用

由网友(不羁)分享简介:我有路我要创建一次,并添加矩形到它。I have Path that I'm creating once, and adding Rect to it.在某些情况下,我通过 Path.offset(...)或 Path.transform(...)然后我无效画布重绘的路径。On some event I'm of...

我有路我要创建一次,并添加矩形到它。

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

在某些情况下,我通过 Path.offset(...) Path.transform(...)然后我无效画布重绘的路径。

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.

我用 Path.computeBounds(...)检查路径边界和我看到的矩形感动。因此,我不明白为什么 Canvas.drawPath(...)不重绘在新的地方的路径。

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);

有什么建议?

推荐答案

我测试的问题与 Path.offset(..)针对Android 4.1及Android 2.3的:

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

在Android 2.3的偏移(..)工程确定。 在搭载Android 4.1它无法显示的路径新的位置。它毕竟是感动!如果我返回到主屏幕(中央硬件按钮我的三星),然后重新启动应用程序 - 它显示了正确的位置。 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...