How to selectively redraw views on Android ScrollEvent?

The screen needs to be redraw on a scroll so the only way to achieve what you want is to cache your View (using View's drawingCacheEnabled property. ) This is however costly in terms of memory. Why don't you simply change your draw() code to only recreate your expensive bitmap when it has changed?

Up vote 0 down vote favorite share g+ share fb share tw.

I have a Layout which as a ImageView, ListView, some TextViews etc wrapped in a ScrollView. Whenever the user scrolls the Parent View calls all the child view's draw() methods. Since my ImageView is a complex bitmap constructed on the fly the scroll really becomes laggy because my imageview's draw() is called continuously, which delagates to ImageView.onDraw() and which in turn delegates to my complex ConstructMyBitmap.draw() and redraws my bitmap every single time.

I need to suppress this imageView.onDraw() call on scrollevent. I don't want to redraw my complex bitmap everytime when a scroll happens. How to identify scrollevent inside onDraw()?

Or is there a better way to handle this? To Romain Guy: protected void onDraw(Canvas canvas) { super. OnDraw(canvas); if(chart!

= null && chart.shdRedraw()) { chart. Draw(canvas); }else { //Do nothing - Canvas should retain the old data } // :-) Happy, Now I control when the chart shd be drawn but.. :-( } Unfortunately when onDraw() gets called onScroll event and I decide not to draw the chart the result is a blank chart area. The canvas given to me in the onDraw() doesn't contain the previously drawn information.

Don't know whether onDraw() flushes the canvas? Any guidance on this? Android android-layout view android-imageview android-scrollview link|improve this question edited Mar 9 at 1:52 asked Mar 8 at 19:10AKh283315 67% accept rate.

Thanks Romain. I have moved away from the bitmap. Now I am trying to draw my chart(my expensive item) directly on ImageView's canvas selectively only when something has changed within the chart.

– AKh Mar 9 at 1:42 but I am facing a new challenge... see check the above question description. I have added more details and code snippet. – AKh Mar 9 at 1:53 1 You need to draw something every time draw() is called.

Drawing in a bitmap is a good idea. If the chart has changed, update the bitmap. If the chart hasn't changed, don't update the bitmap but draw the bitmap on screen anyway.

– Romain Guy Mar 9 at 19:22.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions