I want to create a list with some text and a photo miniature in each row.
So I created a row layout with a TextView and a ImageView, my question is how do I make the ImageView just a little square and then make an image adapt to the size of the ImageView?
<ImageView .... android:scaleType="centerInside" />
Set full screen image as an image resource of this image view. It will be downscaled automatically.
Additionally you can limit width and height setting android:maxWidth and android:maxHeight attributes to prevent minature to be too large.
my recommendation is you do not scale the image to fit the view as this is an expensive operation and will slow down your app it is preferable to prescale the item to the size you want.
Take a look at this Strange out of memory issue while loading an image to a Bitmap object. It's a correct way to get miniature with minimum memory consumption.
Related
i have some image (either resource image or bitmap image)
what is the major difference between showing them in ImageView or set them as background in LinearLayout.
any difference in Quality or Memory usage ?
what is the major difference between showing them in ImageView or set
them as background in LinearLayout.
When you set a background to a layout.It may re-size and change the shape of the image.So it may change your expected output view.
ImageView is specially designed for setting images and it has extra features like android:scaleType, you can set the exact image and use function like crop.
any difference in Quality or Memory usage
Image view is a view and it will reduce the computation of loading the layout each time while using a layout for this porpose.
I am developing an android application using Google app engine.We have custom list view in which image has to be shown. I have used lazy loading for list view to load more data on demand.But problem is here, I am getting images from server, User can upload images of any size. Being used such images by user, I am not able to manage height and width for every image in list view List view is looking very ugly. How can I manage such images in specific height and width in image view?
Please share your best answer.
Thanks,
Prashant.
You can use the Google Images API for this. It has the capability to resize images have a look at
https://cloud.google.com/appengine/docs/java/images/
Using this you can
Resize
Rotate
Flip horizontally
Flip vertically
Crop
any image at runtime
Now when fetching the images use resize to scale down images to a specific dimension and use it in your listview
Simply there are 2 options.
Use android's ImageView.ScaleType
http://developer.android.com/reference/android/widget/ImageView.ScaleType.html
ImageView iv = someView;
iv.setScaleType(CENTER_CROP) // also CENTER_INSIDE, CENTER, whatever you want.
or in xml
<ImageView
...
android:scaleType="center" />
use blobstore magic url
https://cloud.google.com/appengine/docs/python/images/functions#Image_get_serving_url
I have a quiz app created however the images are different sizes. Would it make sense to use a gridview for one image or is there a way to make sure imageview is set to the same size for different images?
You can limit the ImageView size instead of use wrap_content just write a static number for example
300dp
the image will fill the ImageView no matter how big the picture is.
I need to crop and center an image to make a thumbnail for a list, but I want the size of the thumbnail to be proportional to the screen size, so that when the list is shown on a tablet or on a phone the image can be perceptible.
Any idea how can I do this?
You can use an ImageView to display the thumbnail.
Set the size of the ImageView in the layout XML, where you can set a different size for each screen size, by following this guide: http://developer.android.com/training/basics/supporting-devices/screens.html
Make sure the scale type of the ImageView is set according to your need by setting the correct android:scaleType property to your ImageView. The available scale types can be found here: http://developer.android.com/reference/android/widget/ImageView.ScaleType.html
That should do the trick.
I have full-sized image files stored on the phone's filesystem, and a method for loading a thumbnail version to be used in a ListView. I basically use the sub-sampling technique that is discussed often on SO and also here.
The method outlined in the link requires you to provide a target width and height in pixels for the sub-sampling to work. For my list view, this is fine because the thumbnail width/height are defined as dimension resources, and are easily converted to pixels. The ImageView that these are loaded into use a scaleXY scale type.
In addition to the list view, I have a separate detailed view where I want to display the selected image as a banner at the top of the screeen, but using a scale type of center (no resizing). The target ImageView is within a RelativeLayout with a fixed height (set in the resources area), and the width set to fill_parent.
So I have 3 questions:
Given that I don't want any special resizing done on the banner image (scaleType is set to center), is the sub-sampling technique still applicable here?
If the answer to #1 is yes, then I would need to be able to calculate the target view's width. Since the width (unlike the height) of the target ImageView isn't fixed like the thumbnail view, how can I find what the effective width the fill_parent ends up as?
If the answer to #1 is no, then how can I efficiently load this image into the view without risking a memory exception?
Thanks!