Reputation: 9394
I want to make the following :
get canvas
draw list of rectangles and bitmaps on the canvas based on for loop
after drawing all items don't call onDraw until I rotate the device, because the application is too slow when I try to navigate through it
My Canvas is in HorizontalScrollView
and When I try to scroll it is very slow
EDIT : I'm extending View class, so can I save the view and don't call onDraw unless I want it invalidate ??
EDIT 2 : This is my onDraw Method
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
for (int i = 0 ; i < mIcons.size() ; i++) {
prepareItem(canvas, paint, mIcons.get(i));
}
}
please any one can help ??
Upvotes: 2
Views: 3672
Reputation: 121
For me it worked by calling return;
after an if condition. Like:
if(lengthX == lengthTotal) return;
Upvotes: 0
Reputation: 9394
I have found a workaround to make this work, I have draw in bitmap and every time I try to call onDraw() I check if my bitmap is not null use it
Thanks All
Upvotes: 0
Reputation: 3127
You can't prevent onDraw from being called but you can override it and use flag which will tell whether it should execute or not. I don't see your code but I suggest you something like:
boolean callOnDraw = true;
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
if(callOnDraw){
for (int i = 0 ; i < mIcons.size() ; i++) {
prepareItem(canvas, paint, mIcons.get(i));
}
callOnDraw = false;
}
}
And when you want stop drawing you set flag callOnDraw = false;
Upvotes: 1