Android: Stretch & Crop Image (but remains Aspact-ratio) - android

I would like to stretch and crop an image so that it shows full screen on a Android device.
For example, inside the red-rectangle above would be the only area displayed on the phone.
I want it to center and crop. If the height of the image is small than the height of the device, I want to stretch the image as well.
By the way, I don't NEED images to be cropped. I just want my ImageView to display only the reg-rectangle part given the landscape image.

Have you tried setting android:scaleType="centerCrop" on your ImageView in XML? If I understand what you're asking for correctly, it should do just that.

Related

Getting an Imageview all screen wide and not distorted

I am working on an Android app. There I have a recyclerview which is populated from a remote server JSON file.
On the recyclerview there is as Imageview.
The image that is shown at the Imageview may have different orientations. It can be portrait, landscape or square.
I could use the scaletype attribute to get the image output as desired, but my client wants to show the image always at full screen width.
And on the other hand, I need to put a reasonable limit for the height attribute.
That means, I need an Imageview with a specific height range (150dp-250dp for example) and then I need the Imageview attribute to full screen width.
I am using Glide to download the images from a remote URL.
What should I do first to get an image not distorted in any of the three cases, portrait, landscape, square?

Unity UI Image Center Crop

I am working on listView item in Unity and stuck at fitting the image properly in UI Image. I tried multiple things using Preserver Aspect Ratop, using Filled image type almost every thing but could not make it look fine. In android we call it center crop what i am trying to achieve. First image is with Preserve Aspect while the second one is without it.
What should i do to achieve it.
Thank you.
This is one way to do it that I can think of, using 2 images. The outer image is set at your desired size and have a Mask component:
The inner image is set at center of the outer image and scaled to fit the outer image (either programatically or by hand) It will be cropped by the outer image's mask and only display the area you want.

Pictures in landscape mode on 1920x1200 tablets appear pressed

I want to place a picture in an app on tablet, with resolution 1920x1200 and the picture is the exact same size, but the problem is the software buttons on the bottom have some height and make the picture pressed on the top and bottom sides... How can I know whats the height of the software buttons, and do I have to manually cut every picture, or can I make it programatically?
Or even better, can I just make somehow the picture take the whole screen, and the bottom end ot just go behind the software buttons?
You can try using this if you want to crop the overflowed part -
android:scaleType="centerCrop"
Or alternatively, you can use this if you want to stretch your image to fit the ImageView -
android:scaleType="fitXY"
Also if you want to Fit image into imageview, keeping the aspect ratio and then resize imageview to image, check this - Click Here

Android ImageView scaleType

I have an image to be used a background in activity:
I want this image to fit screen by its height.
It means that for wide-screen smartphones, I want my image to be fit by height and centered:
and for square-screen smartphones, I want my image to be cut:
I use ImageView for the image. What scaleType should I use? Looking at the second figure, I'd say to use android:scaleType="centerInside". But looking at the third, I'd say to use android:scaleType="centerCrop". What is correct?
Your evaluation of the different scaleType's is correct. If you want the whole image to be visible, use "centerInside", or if you want to fill the whole view then use centerCrop.
To use a mix of both, you can set the scaleType in your onCreate() method. Based on the behavior you want to have, you can check the orientation or size of the screen and set the appropriate choice.
imageView.setScaleType(ScaleType.CENTER_INSIDE); // or ScaleType.CENTER_CROP
You can have two layouts, one for each of your configurations. You can then load the proper one at the activity's onCreate() call.
When you fit one side of image to background, you will face with two problems, first one is screen width is bigger than image's width or screen height is bigger than image height.So you will have empty space.
If you do not want to face with resolution problem and you want to fit both side of image to background, you need to use centerCROP.But as i said, if one side of image is not enough to fit background, image gets bigger till it will be filled.
Use centerCrop because centerInside doesn't scale an image in a view and you have to create the image with appropriate height to achieve wide-screened smartphones background filling. Or alternative you could use fitCenter to get uniformly scaled image by both axes which fills the all background.

Android - How to implement Vertical Scroll in an ImageView

I'm creating an app in which on click of listview items I'm showing images. Now the size of those images is generally width:480 and height is variable, most of the time > 800.
I'm using ImageView to show those images.
Now if I use simple imageview and show the image as setContentView(R.image), the image fits itself EXACTLY to 480x800 which results in distortion of image content.
I tried to implement suggestions given at
Android: Scrolling an Imageview
but again no luck. Here I'm able to get the scrolling of the ImageView but not what I want.
What I want is that the image doesn't change it pixel ratio. It simply shows to the user on the screen (full screen width) and with a vertical scroll to see the content that is beyond the 800 px ratio.
Kindly suggest what should I do in ImageView XML and my activity class to achieve the same.
Currently i'm implementing everything in Android: Scrolling an Imageview so code is same as it's there.
Try wrapping the ImageView in a ScrollView.
And don't forget to set the ImageView's scale type to something like FitXY.

Categories

Resources