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
Related
I wan't to insert in my SimpleDraweeView with
android:layout_width="50dp"
android:layout_height=50dp
some picture, that may be bigger than this dimensions. I want to resize picture proportionally, so for example picture with source dimension 117x81 should show like 50x34. What should I do to that the picture is not circumcised, but decreased proportionally.
You should set actualImageScaleType in you xml and choose centerInside option. Do not use android:scaleType since it does not have effect on Drawee.
Please take a look at other available options as well.
Reference link: Fresco Drawee Scaling
You can doing that with is code:
simpleDraweeView.getHierarchy().setActualImageScaleType(ScalingUtils.ScaleType.CENTER_CROP);
I am going to show some images, but my constraint is as title. I want to make all images have same height but according to their width they must have different width. I just do not want to lose any part of the image when scaling. here is my code:
<com.android.volley.toolbox.NetworkImageView
android:id="#+id/ImageView_IssueFirstLookActivity_magas"
android:layout_width="wrap_content"
android:layout_height="170dp"
android:layout_marginLeft="32dip"
android:layout_weight="2"
android:maxWidth="40dp"
android:adjustViewBounds="true"
android:scaleType="fitStart" />
I tried all I could with different values of android:scaleType but get nowhere.
here is a figure that what I want but when I play with those properties it dose not scale it as I want for example some time it dose not show image width completely and it crops it badly. Another try for example is android:scaleType="fitStart" which cause the width of my images to be fine but the heights are not fit anymore. Any idea?
andriod ImageView attributes does not support the requirement you said just by statically choosing combination of width,height and saleType in the layout xml.
Instead you can do it in the java code by actually finding the width for the image for a given fixed height and setting them programattically to each view in dp(make sure you do the pixel to dp calculation for achieving right output, salable across devices)
If you don't mind an extra dependency, you can do it with Picasso
Picasso.get()
.load(R.drawable.my_image_resource)
.placeholder(R.drawable.ic_image_placeholder)
.error(R.drawable.ic_broken_image)
.resize(0, (int) imagefixedHeight)
// optional:
// .centerInside()
.into(myImageView);
I am setting a imgage in an ImageView. I want to scale down the image size without reducing the imageview size. Please guide me step by step.
Use scaleType parameter for your imageviews and set the value to centerFit or centerCrop. More here: http://developer.android.com/reference/android/widget/ImageView.ScaleType.html
Taken from this link: source
You should also see android:adjustViewBounds to make the ImageView resize itself to fit the rescaled image. For example, if you have a rectangular image in what would normally be a square ImageView, adjustViewBounds=true will make it resize the ImageView to be rectangular as well. This then affects how other Views are laid out around the ImageView.
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"
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.