how to load internet images in gridview efficiently?

前端 未结 3 804
情深已故
情深已故 2021-01-31 06:42

I am using following example to display internet images in my activity.

http://developer.android.com/resources/tutorials/views/hello-gridview.html

In custom imag

3条回答
  •  青春惊慌失措
    2021-01-31 07:11

    You will need to implement the caching yourself. Create a proxy class that will download the images. In the getView ask this class to download an image by passing a url. In the proxy class create a HashMap that will map a url to a Bitmap. If the key for the passed url doesn't exist, download the image and store it. Otherwise returned the stored bitmap converted to an imageView.

    Of course you can't afford to store as many images as you like. You need to set a limit, for example 10 images, based on the image size you expect to have. When the limit is exceeded, you need to discard old images in the favor of new ones.

提交回复
热议问题