不推荐使用的Canvas.getMatrix()的替代方法是什么?

问题描述 投票:25回答:4

我有以下代码片段,该片段使用画布的当前转换矩阵来转换一组边界。

    final RectF bounds = renderer.computeBounds
    activeCanvas.getMatrix().mapRect(result, bounds);
    return bounds;

但是,在最新的API级别(16)下,我得到警告提示

The method getMatrix() from the type Canvas is deprecated

API 16 Diff Specification确认。

这一切都很好,但是关于Canvas.getMatrix()的当前文档没有提及弃用,也没有提供替代方法。作为一种解决方法,我现在只是禁止显示此警告,但是我真的很想知道执行此操作的new and Improvement(tm)的方式。

android android-4.2-jelly-bean
4个回答
8
投票

矩阵现在由视图而不是画布处理。不幸的是,我无法向您解释Google在这一方面的决定,但是您应该能够通过两种方法重现相同的内容。


9
投票

[我认为由于issue with getMatrix when hardwareAcceleration is enabled,他们已弃用它,正如kouray所说,现在矩阵已由视图处理。


3
投票

如果您无权访问视图:

要变通解决此问题,在大多数情况下,您可以使用canvas.scale(),canvas.translate()等应用任何转换,而不是检索矩阵,对其进行修改然后重新设置矩阵。

由Sandeep引用,来自Google issue with getMatrix when hardwareAcceleration is enabled。>>


0
投票

如果您无权访问视图:要变通解决此问题,在大多数情况下,您可以使用canvas.scale(),canvas.translate()等应用任何转换,而不是检索矩阵,对其进行修改然后重新设置矩阵。如Sandeep所述,当启用hardwareAcceleration时,来自Google的getMatrix问题。

© www.soinside.com 2019 - 2024. All rights reserved.