Smartest way to draw 100+ images on screen - android

I'm going to draw a grid of 10x10 PNG images. Each image is 32x32 px. All of the images are unique. I'm thinking that the easiest way seems to be to put each image in an ImageView.
If adding all ImageView's to the layout would this give me some kind of performance hit?
Would there be any smarter way to draw these images?

I assume that your grid is a gridview. Than it should have an adapter with your items. There is a getView method in the adapter you need to take look into. You set your images there.
I would look at GridView examples and this example
http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/view/List14.html
to take a look how to write efficient adapters.

Related

android: most efficient way to repeat an image

I am doing a project where I want 100 of the same image randomly scattered throughout the screen. In the future, I want an image to disappear when the image is tapped by the user.
I am mainly focusing right now on the most efficient way to display a repeated image. It seems like I could set it up so that the fact that the images are the same makes it more efficient; I'm just not sure how. I do not want to proceed further until I know I have a sound base. I'm using .png files.
I've looked around without a definite answer.
Also, would if be easier to draw my object with two circles (which is what my image is), rather than using a bitmap?
Any clues???
Assuming you're talking about drawing the bitmap on a Canvas object, the method should be pretty straightforward. You load the image into a Bitmap object and keep it as a member of the owning class, and draw it 100 times using canvas.drawBitmap(...) functions.
The other way of doing it is having 100 ImageViews with the same image, but I won't even write the details because this would be truly inefficient!
You can use a listView: http://developer.android.com/guide/topics/ui/layout/listview.html
It shows a list of items, using an adapter to inflate elements. It is pretty simple to use.

how to layout images

I have a lot of images in scrollview, I would like to know how to layout them so they would be seen the same on different resolutions. Like if I rotate screen some images would fill the gap.(All activity is only images)
You can use GridLayout.
Check Heterogeneous GridLayout,GridLayout and Row/Column Span Woe.
It might helpful for you.
This issue is behond displaying an image on a gridView but rather about memory limitation and caching(recycling and reusing etc..)
Take a look at this link Displaying Bitmaps Efficiently and try to download a sample on the left called BitmapFun.zip

Most efficient way to display a grid of images

What is the most efficient way to display a grid of random images on android?
I have a list of random album art images, I need to generate a grid out of them and use it as a background in my activity, the images are downloaded asynchronously, scaled down and cached, displaying them in a grid seems to consume a lot of RAM,(yes I'm recycling the bitmaps, and using LRU cache)
Would drawing them to a canvas be a better solution? Are there other efficient ways to do that?
Is the GridView safe, are there any guarantees that it won't run out of memory?
P.S. drawing them to a canvas would require me to redraw when the orientation or activity's size changes.
I donĀ“t think there is a more efficient way, at least I can not think of one right now. What you could do, that depends if grid view is necessary, is using the Image carousel from Romain Guy which is made in Renderscript. I do not have the URL at the moment but it is a google-code project.
Another page where sometime are good stuff for those things is http://www.theultimateandroidlibrary.com/all
The LRUCache is really nice and fast and should do the trick. I also would be interested in a more efficient way.....

Create custom Imageview component that has a custom picture frame

I would like to build a custom component (extending from ImageView I guess) that display an image inside a frame specified by the user (the frame is a custom image) with inner rounded corners (Pinterest user icon like).
I started finding how to compose two bitmaps but it is a difficult matter so I am wondering if there is some opensource component/tutorial to better understand how to achive it.
The frame picture is a nine-patch png (I didn't understand how to load and scale it properly into a bitmap).
Thanks
Have you checked out this
Seems like it does the job, although I'm not sure how to implement.

How to zooming whole gallery?

I try to display images with gallery view and it works fine, now I would like to add a zoom but the WHOLE gallery, not selected image.
The point is that all images are expanded and increased spacing between them.
How to do it?
Not sure how you plan to do it, but if you just simply change all the candidate image size, the space among them would get bigger proportionally.
You can try setup the style of each frame in the gallery view. Steps are like:
1. override the gallery adapter, implement the getView funciton.
2. for imageView, setLayoutParams, setScaleType, both of which can be reference in the imageView doc, read the doc and adjust the params.
Put images into WebView. Actually make html page referencing your local images, put it into <table> element, and let WebView provide zooming. This will be fast, hw-accelerated, and will zoom as you desire.
Would it be good solution to change size of Gallery widget from code as well as space between images, according to zoom level, so it fits to your needs?

Categories

Resources