Showing thousands of ImageViews in android - android

I need to load a lots of images (3500 images) to my android app (and then I will rotate with each of them in the application). But when I load each of them separately (creating new ImageView which I add to the array) then it takes about 10 seconds to load. I have tried to inflate them from XMLs since there is only 8 different images which I use but no visible changes.
I would be really grateful for any advice how to load it faster.
EDIT: I am creating a grid of hexagons, each hexagon is consisted of 6 triangles (this way I need to store only 8 different triangle images instead of storing image for each different hexagon). After the grid is loaded user can resize it. I need to load all the grid cell at once because there are many constrains between them. Also only operation I will do with the hexagons is to rotate them.

You can use cashing for bitmap images, the following tutorial link is helpful.
http://developer.android.com/training/displaying-bitmaps/cache-bitmap.html

Related

What's the best way to place multiple images onto the screen simultaneously?

So my app needs to have a maximum of 50 images on the screen at the same time in a FrameView, they need to be placed on top of a base image. If I put these images into drawable, the app crashes after a few images are placed with an OutOfMemoryError. But it works when I put the images in mipmap for some reason without crashing. So I placed them all into the mipmap folders. The images are VERY small too, the largest among them is 2.2 KB and the smallest is 398 bytes. The app works as intended, but performance is horrible after you place a few images onto the screen. The first few images will load quickly, but as you continue to place images onto the screen it gets progressively slower to the point where it may take multiple seconds to place the image onto the screen. I'm just using an ArrayList to put all the Drawables in, and then another ArrayList to put all the ImageViews and I load them into the view within my onTouchListener. Here's an idea. The index is used to decide which image is to be inserted:
drawableOverlays.set(index, getResources().getDrawable(R.mipmap.exampleImage, null));
imageOverlays.get(index).setImageDrawable(drawableOverlays.get(index));
frame.addView(imageOverlays.get(index));
I've also tried using Glide and Picasso and those loaded in even slower. Am I approaching this wrong? Is there a more efficient way to accomplish this?
The best way is create a RecyclerView with ImageViews as items, and then load the images with Glide or Picasso, any of those libraries will give you the best performance

RecyclerView stutters when scrolling only 14 images

I've been trying to create a Recycler View full of Card Views. Currently, I'm using the Recycler View from this tutorial and loading it with 14 different images. The professional quality images range in size from 134K to 242K.(Down from 8MB - 18MB)
I know that the images may be too big but, I feel there must be some way to get better performance while scrolling. Can someone point me in the right direction?
Edit: The images will be stored on the device. There will probably never be more than 20 of them.
You can use Picasso library or Android Universal Image Loader
Picasso
Android-Universal-Image-Loader
You don't need any AsyncTask.Theese 2 library handling image operations in background so you can keep scrolling smoothly. I am using Picasso in my project right now. You can add error drawable , temporary placeholder default drawable , and its so simple automatically caching.
Just use one of them in onBindViewHolder to bind any image to imageView
Load the images in a separate thread (or AsyncTask).

Load multiple large images in single ImageView

I have multiple large images and I would like to use these in such a way that it would allow users to do continuous panning. I couldn't stitch all the images into one image as it would give memory limit error. Also I want to compress the images. I believe one option is to place the images in a virtual grid shape and show image based on current viewport & touch position (it might have some issues when switching between images). I was wondering if there is any other easy ways to solve this.
You can split the images into smaller ones and load only the images currently visible on the screen and probably the next one to provide smoothness while panning. So if you have 6000x4000 you may want to automatically split them into 24 images 1000x1000.

Android Fragment Background images

i am new to android and i want to set an image as background to different fragments in an activity.But the images are to large that they make my application to increase in memory and i don't want this. The activity have 6 different fragments and each have different background, here i set the background images from drawable.
i referred this.but i didn't get correct solution.
How could i make them so that the memory size of images will be less?
Android - Reduce the memory usage of Bitmap Drawables
On this concrete case you have 2 options:
1 - Set the image as background on the root view of your fragment Layout. Doing that you'll avoid out of emmory errors, but the image will be scalled to fullfill the whole screen, so it could be diformed.
2 - Use Picasso library http://square.github.io/picasso/ to load the file images. It can be helpful to manage memory issues.
Also, the best thing you could do before starting is to reduce the size of the images using some software such as https://tinypng.com/.
Hope it helps

appropriate container to display images one by one

I am new in android development. And I am building a location based app like google map(To some extent,we are reinventing the wheel :( ).
Like maps.google.com,the map data is generated as tiles in server and re-organized in the client. And in the html page,its easy to find the container to hold the tiles. For example,we can create some img element accordingly, and then put these imgs inside a div element.
Now in the android,which is the appropriate container to display the images?
In fact, I am reading the docs Displaying Bitmaps Efficiently, and it seems that ImageView is the only way to display the bitmaps. If this is true,then I have to create several ImageViewS dynamically according to the tile size and the size of the user screen. Also,according to the docs,AsyncTask should be used for performance enhancement. So each created ImageView will hold a AsyncTask,I am afraid which will out of my control.
So I wonder if there is any other solution can meet my requirement?
BTW,we use the tiles now,but we also have the plan to support the vector data which seems to have to use the opengl,so switch between different map types should be under consideration .
Update:
If as Raghunandan suggested I should use the ImageView to hold the satellite bitmaps in my app,but how about the vector data which should be still drawn use the opengl,then how to switch between these two types(views)?

Categories

Resources