Search code examples
androidandroid-custom-view

Pre-creating a Path that depends on View width and height


I have a custom View that draws a complex Path. The dimensions of path elements are calculated using the view width and height. I need a way to pre-create this path before onDraw is called to "Avoid object allocations during draw/layout...", in a moment when the view width and height are already known. What is the proper moment in the View lifecycle to do such pre-creation?


Solution

  • just override View.onSizeChanged and do your initialization there