What is LazyList?

Asked 2 years ago, Updated 2 years ago, 83 views

I can't find a reliable source code that explains what LazyList is. Help me.

android lazylist

2022-09-22 21:32

1 Answers

LazyList slowly loads images from the sd card or server. You can look at the image in the way that it is loaded from time to time.

Images can be cached in local sd card or mobile phone memory. Url is considered that key. If the key is pointing to the sd card, it retrieves the image from the sd card, otherwise it retrieves it from the server and caches it to the selected location. The cache can be restricted, and the user can also set where the cache image will be stored. You can also initialize the cache.

Instead of waiting for the user to download all the large images and display them on the screen, they load them at that time. Called images remain in cache, so you can view them offline as well, too.

https://github.com/thest1/LazyList

You can use it for getview as below.

imageLoader.DisplayImage(imageurl, imageview);

ImageLoader Display Function:

    public void DisplayImage(String url, ImageView imageView) //url and imageview as parameters
    {
    imageViews.put(imageView, url);
    Bitmap bitmap=memoryCache.get(url);   //get image from cache using url as key
    if(bitmap!=null)         //if image exists
        imageView.setImageBitmap(bitmap);  //dispaly iamge
     else   //downlaod image and dispaly. add to cache.
     {
        queuePhoto(url, imageView);
        imageView.setImageResource(stub_id);
     }
   }

An alternative to LazyList is Universal Image Loader.

https://github.com/nostra13/Android-Universal-Image-Loader. This works (in the same principle) based on LazyList. But it supports a lot of settings. Therefore, I recommend using Universal Image Loader more. For example, if the download fails, you can display an error image, apply a round edge to the image, cache it to memory or disk, or compress the image.

Write the following code in the custom adapter generator.

 File cacheDir = StorageUtils.getOwnCacheDirectory(a, "your folder");

 // // Get singletone instance of ImageLoader
 imageLoader = ImageLoader.getInstance();
 // // Create configuration for ImageLoader (all options are optional)
 ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(a)
          // // You can pass your own memory cache implementation
         .discCache(new UnlimitedDiscCache(cacheDir)) // You can pass your own disc cache implementation
         .discCacheFileNameGenerator(new HashCodeFileNameGenerator())
         .enableLogging()
         .build();
 // // Initialize ImageLoader with created configuration. Do it once.
 imageLoader.init(config);
 options = new DisplayImageOptions.Builder()
.showStubImage(R.drawable.stub_id)//display stub image
.cacheInMemory()
.cacheOnDisc()
.displayer(new RoundedBitmapDisplayer(20))
.build();

You can use getView() with the code below.

  ImageView image=(ImageView)vi.findViewById(R.id.imageview); 
  imageLoader.displayImage(imageurl, image,options);//provide imageurl, imageview and options

Of course, you can set other options as needed.

The viewholder is available for smooth scrolling and performance in conjunction with Lazy Loading / Universal Image Loader. https://developer.android.com/training/improving-layouts/smooth-scrolling.html


2022-09-22 21:32

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.