0

I have an Android custom view that displays a grid of images downloaded from a server. The images are downloaded in the background, after an image has been downloaded, it is added to a list an view redraw is triggered.

So each time an image is downloaded, I draw a background and then the images in the list. This approach causes some flicker to appear. Plus I find it inefficient to draw all images just for one new image.

Is it possible to draw something in the view outside the OnDraw event? Thus I would draw only the newly downloaded image, instead of the whole list.
With Windows Forms I can do this outside the Paint event:

Graphics g = this.CreateGraphics(); // this being a Control (<=> View), Graphics <=> Canvas
g.DrawSomething()
g.Dispose()

Is something similar available in Android or my approach is incorrect?

Surubelnita
  • 107
  • 9
  • you should consider using a recycler view with grid layout manager, no need to write a custom view for such use cases – rahul.taicho Apr 11 '18 at 18:58
  • You can look at the [SurfaceView](https://developer.android.com/reference/android/view/SurfaceView.html) class, and refer to [this](https://stackoverflow.com/questions/37544092/how-to-draw-a-bitmap-to-a-surfaceview). – Robbit Apr 12 '18 at 07:15
  • @JoeLv-MSFT I ended up using the SurfaceView class. If you add your comment as an answer I'll accept it. – Surubelnita Apr 26 '18 at 08:52

1 Answers1

1

You can use the SurfaceView, if your drawing is frequent, this class should be considered, here is how to draw the bitmap on the SurfaceView.

Robbit
  • 4,300
  • 1
  • 13
  • 29