Inspectopedia Help

Wrong Canvas Size

Wrong Canvas Size

In a custom view's draw implementation, you should normally call getWidth and getHeight on the custom view itself, not on the canvas instance.

Canvas width and height are the width and height of the Canvas, which is not always the same as size of the view.

In the hardware accelerated path the width and height of the canvas typically always match that of the View because every view goes to its own recorded DisplayList. But in software rendering there's just one canvas that is clipped and transformed as it makes its way through the View tree, and otherwise remains the same Canvas object for every View's draw method.

You should only use Canvas state to adjust how much you draw, such as a quick-reject for early work avoidance if it's going to be clipped away, but not what you draw.

Issue id: CanvasSize

Inspection Details

Available in:

IntelliJ IDEA 2023.3, Qodana for Android 2023.3, Qodana for JVM 2023.3

Plugin:

Android, 2022.3.1 Beta 2

Last modified: 13 July 2023