I need to display a movie theater map with sectors, rows and seats. Currently, I have about 1000 places (filled rectangles) to draw, and I do this for each place by calling:
canvas.drawRect(seatRect, seatPaint)
My view should also support zooming, scrolling, and scrolling. Performance is terrible. I tried to improve it by explicitly enabling hardware acceleration, but nothing changed. It seems to have been enabled by default on my Nexus 4 (Api 22)
Could you suggest any methods for rendering a large number of rectangles at high speed? Thus, the animation of movement, scaling is smooth.
Custom View Class Code:
@Override
public void onDraw(Canvas canvas) {
super.onDraw(canvas);
canvas.save();
canvas.scale(mScaleFactor, mScaleFactor);
canvas.translate(mTranslateX, mTranslateY);
if (mEventMap != null) {
mEventMap.paint(canvas);
}
canvas.restore();
}
EventMap Code:
public void paint(Canvas canvas) {
for (EventPlace place : places) {
if (place.isSelected())
placePaint.setColor(0xFF00FF00);
else if (place.isAvailable())
placePaint.setColor(place.getColor());
else
placePaint.setColor(0xFF000000);
canvas.drawRect(place.getBounds(), placePaint);
}
}
, onDraw, .
...