ImageView Scaling: fix height variable width with maxWidth - android

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);

Related

How to make imageview's background to scale proprtionally in android?

What i need is that image should be scaled till it retains the exact proportions after that it should not be scaled further, so that every time width is equal to height of the image view.
As if don't scale properly it will get out of shape, and i need it to be in 1:1 ratio of width and height.
Will
Imageview:scale="fitxy"
work in this case ?
Please help thnk you.
I am working on android ICS
To keep aspect ratio, you should make the image the src rather than background.
Take a look at the ScaleType documentation here http://developer.android.com/reference/android/widget/ImageView.ScaleType.html.
You should try using either android:scaleType="centerInside" or android:scaleType="centerCrop".
Hope that helps!
android:scaleType="fitXY"
Fits the screen size of the device.
Try this adding this
android:layout_height="150dp" //or your designed proportion
android:layout_width="150dp" //or your designed proportion
android:scaleType="fitXY"

ImageView as Mask or Parameter for images from web - How to?

I built an app and used an imageview (SmartImageView to be exactly, but i doubt that the problem) as reference for the place where I want my images to be, the thing is: the imageview has 50x50 px (set to wrap_content) but when I pull the images from web (favicons, to be exactly) if they are bigger than 60x60 instead of keeping the imageview size, they keep their own size.
I want my imageview to work as a mask and crop and/or resize the favicons to it's 50x50 size, how can I do it?
Heres the xml of the imageview:
<com.loopj.android.image.SmartImageView
android:id="#+id/favicon_placeholder"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/favicon_example2" />
And here's the java bit of code that pulls the images to it:
linkImageView.setImageUrl(link.favicon);
You are setting your height and width to wrap_content which means that it is going to resize itself to fit the content that you give it. If you want it to always be 50px no matter what size image you give it then you need to declare the size statically instead of wrap_content. And set your scaleType so the system knows how to manipulate the image should it be a different size. See here for possible values
<com.loopj.android.image.SmartImageView
android:id="#+id/favicon_placeholder"
android:layout_width="50px"
android:layout_height="50px"
android:scaleType="fitXY"
android:src="#drawable/favicon_example2" />
note that the use of the px unit is generally discouraged. dp is used more often because it can scale up or down for smaller and larger resolution devices. But if you want it to be the exact same pixels on every device then you must declare it with px
Look at ImageView.ScaleType. You may want to have a calculated size or fixed size in dp when using ImageView.ScaleType properties.

Handle ImageView pictures in Android

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"

Android - Autofit image in ImageView?

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

How to create an ImageView that fills the parent height and displays an Image as big as possible?

I have an ImageView that is defined in the following way:
<ImageView
android:id="#+id/cover_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_below="#id/title"
android:layout_above="#id/divider"
android:adjustViewBounds="true"
android:src="#drawable/image_placeholder"
android:scaleType="fitStart"/>
Now after downloading a new bitmap I change the drawable. The image now appears in the top left corner of the ImageView. Is there a way to have the image fill up the whole height that is possible and then adjust the width of the view to enable scaling the image without changing the ascpect ratio?
The image fills up all the space on a standard screen but on a WVGA Resolution the image takes only about half of the actual height of the ImageView.
If I'm understanding you correctly, what you need to use is the centerCrop scaleType. fitStart scales the image proportionally, but neither the width nor height will exceed the size of the view, and the image will, as you said, have a top|left gravity.
Using centerCrop scales the image proportionally, but causes the shortest edge of the image to match the size of the view, and if there is additional data on the long side that does not fit, it is simply cropped off. The gravity is, of course, center. The below worked for me:
<ImageView
android:src="#drawable/image_placeholder"
android:id="#+id/cover_view"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scaleType="centerCrop"
/>
You can change scale type to fitXY via call to
imageView.setScaleType(ScaleType.FIT_XY);
simply do it in xml like
android:scaleType="fitXY"
Basically the answer here is that there is no predefined value for what you are trying to achieve. The solution is to create a Matrix that fits to your needs and call setImageMatrix(matrix) on your ImageView.

Categories

Resources