I try to use gallery to show image in network.
But when turn left or right to change image.
The image shows delay about 3 seconds to load from network each time.
May it load next image in background when this image showing.
Or save all loaded image in cache, but this may cause out of memory.
My code as below:
gallery = (MyGallery) this.findViewById(R.id.gallery_photo);
gallery.setAdapter(new GalleryViewerAdapter(this, URL));
URL is string array of URL.
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ImageView iv = new ImageView(this.mContext);
try {
URL aryURL = new URL(URL[i]);
URLConnection conn = aryURL.openConnection();
conn.connect();
InputStream is = conn.getInputStream();
Bitmap bm = BitmapFactory.decodeStream(is);
is.close();
iv.setImageBitmap(bm);
iv.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
return iv;
}
How to modify my code can avoid load and lag each time?
Maybe you can try this.