On Wed, Sep 1, 2010 at 11:09 AM, Robert Schmid <[email protected]> wrote: > I am creating an app with a very long horizontal custom view (about > 500 pages horizontally). I don't draw to it often enough to justify > using a surface view.
That would seem to be bad from a memory consumption standpoint. For example, a ListView on an ListAdapter with 500 rows does not create 500 row Views, but rather only as many as can be shown on screen. That's a performance optimization, to minimize runtime memory usage. ScrollView/HorizontalScrollView do not do the same, forcing you to allocate "500 pages" worth of content up front. > As I approached the problem I inserted my custom view into a > horizontal scroll view and that works OK. Still, I think it can be > smoother. Right now it redraws the whole bitmap each time. So I > tried creating the bitmap by hand and discovered that it is too large > - the VM won't allow the memory to be allocated. This is, of course, > a big clue to how the HorizontalScrollView draws to the canvas. So, > I'd rather redo the onDraw function to use a smaller bitmap. I don't > quite understand, though, how the bitmap, canvas and > horizontalScrollView are related and I need some strategy suggestions > as to how to go about this. I'll be stunned if you can successfully do "500 pages" of bitmaps in memory at one time, which is what HorizontalScrollView will require. You could look at the code for ListView (and AbsListView) to see how they do what they do. That's a few thousand lines of code and, I suspect, took a few engineer-months to get to its current state. -- Mark Murphy (a Commons Guy) http://commonsware.com | http://github.com/commonsguy http://commonsware.com/blog | http://twitter.com/commonsguy Android App Developer Books: http://commonsware.com/books -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en

