Things looked quite simple first but in the end the result is not good.
I have an image which has a width larger than screen's width. So I need to scale it down in my imageview. I looked over the ScaleType options and tried them all but none is ok. First "center" only displays the image centered on the layout, no scaling done. "fitCenter" scales the image to fit in my layout but has a major drawback: the height of the item remains as it would have the large image in it. Take a look at the second screen in the attached image. How can I force the list item, to reduce its height to wrap both the text and the image ?
Use the scaletype which seems best to you ( I guess you like what you see with fitCenter). The additional thing that you must do is
android:adjustViewBounds="true"
in your ImageView.
or you could go with FitXY but sometimes the result is not exactly what you want.
use android:scaleType="fitXY"
Could you use FitXY?
This would work if you knew the size of the area you were putting the image into.
CentreInside may also work, I've used this to scale down images, but I think it depends if you've control of the size of the bounding layout element.
You either need to set android:height = "wrap_content" on your outer container, or set static height of TextBox and give ImageView android:weight = "1" so that the ImageView takes remaining space in container.
Related
i have a question about pictures in an ImageView in Android.
My problem is, that the pic i wanna show in my ImageView seems too big for my smartphone screen. Therefore it is not on the place i set in the xml...
Here is a pic that you know what i mean: http://www10.pic-upload.de/31.10.12/iuebxzkvr3e.png
The grey area is my Banner which should be located on top of my activity...
If i scale the pic, it should work (the smaller, the higher till it fits), but i think other smartphones with a different resolution should have the same problem again with my app..
Here is my XML:
<ImageView android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/ivBanner"
android:src="#drawable/banner"/>
Nothing special.
thanks in advance
In your layout you should set its height and width to absolute dp values:
Here is a px to dp converter:
http://labs.skinkers.com/content/android_dp_px_calculator/
That solved the problem for me, for every screen size you need a different values(hdpi/xhdpi).
you can set scaleType for ImageView to fitXY, or centerCrop
android:scaleType = "fitXY"
Is there a way to proportionally set the height of an ImageView if the width is set to android:layout_width="fill_parent"?
It appears there is no direct way of adjusting an ImageView without skewing one of it's dimensions. This seems bizarre given the application is expected to support a slew of screen sizes and resolutions.
You can use wrap_content for the height and set the correct scale type (either in code or via the android:scaleType attribute in XML). You are probably looking for CENTER_INSIDE/android:scaleType="centerInside".
See ImageView.ScaleType
I have several images I lazyload into a ListActivity. Now the thing is that the images have different aspect ratios.
I would like all images to display with the same width set in xml (to fit into my layout), while taking as much space hightwise as they need.
Is there a way to do that in xml?
Thanks!
I think you want android:scaleType="fitCenter"
From the sdk docs at http://developer.android.com/reference/android/graphics/Matrix.ScaleToFit.html#CENTER:
Compute a scale that will maintain the original src aspect ratio, but will also ensure that src fits entirely inside dst. At least one axis (X or Y) will fit exactly. The result is centered inside dst.
So, I think if you set a width on the imageview but set the height to wrap_content you should get what you want with the scaleType fitCenter.
I will be displaying an image in an ImageView that will always be much higher and wider than the size of the screen. Is there a simple way to scale the image down so that it fills the ImageView exactly?
Try setting up the scale type in the xml, i believe it scaleXY is the one you are looking for scale types
<ImageView
android:scaleType="scaleXY"
android:src="#drawable/my_image"/>
If you're loading the view in XML, the android:scaleType parameter should do the trick.
http://developer.android.com/reference/android/widget/ImageView.html#attr_android:scaleType
New to Android, bad with layouts so this is probably a simple solution but I can't find it. I am adding an image to a ListView, the ListView is defined like this:
<ListView
android:id="#+id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"/>
Image is added like this:
ImageView image = new ImageView(context);
image.setScaleType(ImageView.ScaleType.FIT_CENTER);
image.setAdjustViewBounds(true);
image.setImageDrawable(drawable);
return image;
in the ListAdapter. I want the Image to scale so the width fills the screen and the height adjust proportionally. What is happening is the image is scaling down so the height fills the list row but there is plenty of room for the width to be bigger. I had this working earlier but can't figure out what changed. Why is the image shrinking to some seemingly arbitrary height and how do I get it to fill the screen by width?
Edit:
So this happened when I started building for 1.6 instead of 1.5, probably a resolution thing. I guess the image is a bit sharper when it's small but I want it larger, it's almost unusable smaller and I am not able to get a larger image, it's from the web.
I think there is no really "simple" solution, but it's already answered here (without list's, but i don't think it matters):
Android: How to stretch an image to the screen width while maintaining aspect ratio?
Have you tried ImageView.ScaleType.FIT_XY ?
Scale Types