Fixed
Status Update
Comments
ro...@android.com <ro...@android.com>
ro...@android.com <ro...@android.com> #2
When hardware acceleration is enabled, a View's drawing commands are recorded in a display list. At this point, a call to getMatrix() will only return the matrix built by the View itself. Any operation performed by the parents will not be taken into account (and cannot be taken into account, a display list can be generated before a View even have a parent.)
The documentation will be updated to explain this behavior.
The documentation will be updated to explain this behavior.
bi...@gmail.com <bi...@gmail.com> #3
But even if I turn off hardware acceleration, the call to `getMatrix ()` returns no parent operation.
Although there will be no problem after I calling `canvas.setMatrix(canvas.getMatrix())` at this point, it also shows that the internal mechanism may be more complex, that is, how the matrix injected by `setMatrix ()` will be used.
Although there will be no problem after I calling `canvas.setMatrix(canvas.getMatrix())` at this point, it also shows that the internal mechanism may be more complex, that is, how the matrix injected by `setMatrix ()` will be used.
Description
The same problem occurs, when using canvas.getMatrix(myMatrix); canvas.setMatrix(myMatrix), and when, between the calls to getMatrix() and setMatrix(), transformations are applied to the matrix. Simply applying transformations to the canvas (e.g. canvas.translate(10, 10)) work as expected.
It seems that the call to getMatrix() returns the matrix relative to the view the canvas belongs to, whereas setMatrix() set's the matrix relative to the entire screen (including status bar, title bar, etc.). When, for example, drawing to an empty screen with just the Android status bar (the one that indicates notifications, battery level, time, etc.), coordinate (0, 0) seems to lie just below the status bar when not applying any matrices (or switching off hardware acceleration), but it seems to lie in the very top-left corner of the screen (i.e. the top left corner of the status bar) when doing described matrix operation and using hardware acceleration.
The expected behavior would be to have (0,0) lie right below the status bar, such as when not doing any matrix operations or switching off hardware acceleration.
I've attached a sample program that illustrates the problem. I've run the program on my Nexus Galaxy running Android 4.0.1.
To work around the problem, in most situations (such as mine), you can apply any transformations using canvas.scale(), canvas.translate(), etc. rather than retrieving the matrix, modifying it and then setting the matrix again.