-1

I'm currently building an app for learning purpose (new to android programming) that lets the users to upload image to the server and watch other users images (by swipe the screen for example).
I finally succeeded to let the user upload image to the server and I was wondering how to code the part that retrieve the images from the server and present them in the app. Assuming I have at the time million images, I don't want the app to load all the images in the same time because it will take a lot of time. And all the guides I'v seen makes the app to load all the images at once. So my question is what is the recommended way to do so?

Hope I was clear. Thanks.

OA617
  • 76
  • 6

3 Answers3

1

Let's say you have an array with a million images in your server to load in your app that will be shown in a RecyclerViewand assuming a screen can fit about 5 images.

In this case scenario a good approach would be to fetch 10 images at a time and load them in a RecyclerView. Load the first 10 images and once the user reaches the end of the scroll load some more images, add them to the previous retrieved image list, and finally update your RecyclerView to present them. With some effort you may be able to create a Facebook look alike effect.

RecyclerView has methods that will easily help you detect the end of scroll (there are plenty of ways you can find in StackOverFlow). Every time you detect an end of scroll, just upload more images.

This is one example: How to know whether a RecyclerView / LinearLayoutManager is scrolled to top or bottom?

Ricardo
  • 9,136
  • 3
  • 29
  • 35
0

Use FlexBox Layout for better UI Design to show images

0

https://github.com/google/flexbox-layout

See how this cat images are shown using FlexBox Layout