I have a custom view (width = 2000) inside a horizontal scroll (width = 480). So there is a scrollable area.
When onDraw() is called, the dirty rectangle ( getClipBounds() returns) returns all the dimensions of the view, so I draw the whole view, including the area that is not visible. As a result, when I scroll, onDraw() no longer called because the areas that become visible are already drawn and are somehow remembered.
public void onDraw(Canvas canvas) { canvas.getClipBounds(r);
This works great !!!
However, my user view can be as wide as 20,000 or more, and everything starts to slow down. My concern is that the cached drawing uses a lot of memory. I donβt think that the drawing is saved as a bitmap, because it has already crashed, since these drawing commands (lines and text, basically) are saved? Is there a way to indicate that onDraw() should request only the visible part of the view, and when scrolling, it calls onDraw() ? Or is there a different approach?
Thanks!
android view android canvas ondraw
Merlevede
source share