views:

46

answers:

1

I'm designing a custom view which is an X/Y Plot. It's a moving graph that scrolls to the left with time and new Y values are continuously coming in at 10 per second.

I've been able to make it work with an array of integers where the array index is the X value and the integer value is the Y value, but this seems horribly inefficient (Because every time it comes time to re-paint, I have to loop 800+ times to paint the graph). Then we do it all again 10 times a second. yuck.

Can anybody think of a paintable object that I can draw points to and perform some kind of scroll transformation and then just draw the new points each time, rather than the whole canvas?

Any other ideas out there?

Thanks!

A: 

You can use Canvas.drawPoints() and let the Canvas do the work in native code: http://d.android.com/reference/android/graphics/Canvas.html#drawPoints(float[],%20int,%20int,%20android.graphics.Paint) You can also be smart about it start at the offset of the first point that you know is on screen. Also, to do the scrolling you have, somehow, to repaint the whole Canvas. You could also probably play tricks with an offscreen Bitmap.

Romain Guy