Android Poor performance of surfaceview in Listview -
i have android app having layout containing listview, inflated with
layoutinflater inflater = getlayoutinflater(); row = inflater.inflate(r.layout.disc_row, parent, false);
the "r.layout.disc_row" containing surfaceview drawing canvas. each row within listview containing canvas. while scrolling list canvas staying @ place while other elements of row scrolling. think poor behaviour of device. same app not drawing on emulator until clicking on listitem.
is there improve strategy drawing within listviews (no bitmap, lines) maybe paint? emulator sys doing much work in activity.
thanks in advance
attached class
public class drawdiscinlistview extends surfaceview implements surfaceholder.callback { private static final string tag = "discont surfaceview"; public drawdiscinlistview(context context, attributeset attrs) { super(context, attrs); // todo auto-generated constructor stub } @override public void surfacecreated(surfaceholder holder) { trydrawing(holder); } @override public void surfacechanged(surfaceholder holder, int frmt, int w, int h) { trydrawing(holder); } @override public void surfacedestroyed(surfaceholder holder) { } private void trydrawing(surfaceholder holder) { log.i(tag, "trying draw..."); canvas canvas = holder.lockcanvas(); if (canvas == null) { log.e(tag, "cannot draw onto canvas it's null"); } else { drawmystuff(canvas); holder.unlockcanvasandpost(canvas); } } private void drawmystuff(final canvas canvas) { random random = new random(); log.i(tag, "drawing..."); canvas.drawrgb(255, 128, 128); }
}
i did research, share here:
instead of using surfaceview used imageview: used canvas creating bitmap , used bitmap in listview. works fine , without loss of performance.
android listview surfaceview
No comments:
Post a Comment