I have images that have height much greater than width. They can perfectly fit in an ImageView with portrait orientation with fitXY.
However, my problem is with landscape orientation. My best scale I tried is centerCrop. Now I have a small problem: I want to give the user the ability to move up & down, because the height is not fit within screen.
How can I do that?
Note: The pages are in fact book pages. That is why I want to move up & down. I want to initially fit width, with top of image viewed. Then the user can move down to read rest of page.
I found now this perfect open source TouchImageView
Related
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
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.
I've tried as many permutations of scaleType and fillViewport and adjustViewBounds and layout_* as I can think of and none of them do what I want. They either fill the screen but lose the aspect ration (fillXY), cut off a portion of the image (centerCrop), or scale the image down so it doesn't fill the width of the screen (centerInside, fitStart, fitCenter, center, matrix).
Here is one specific example:
Source image is 222x470 pixels.
Emulator screen is 480x800hdpi in portrait orientation.
I want the ScrollView to fill the entire screen.
I want the ImageView to scale the image so it fills the width of the screen (stretching the source image from 222 wide to 480 wide).
I want the ImageView to preserve the aspect ratio of the source image, meaning its height will have to scale from 470 pixels to approximately 1016 pixels.
Since that won't fit on the screen (it is only 800 pixels high), the ScrollView should kick in. By default the top of the image should show and the ScrollView should allow scrolling down to see the rest of the image.
This is just one example. Ideally I'd like this to work regardless of image size and screen size.
Extra credit if you know a way to do it all within the XML layout.
And before y'all come down on me like a ton of bricks (or bricked cellphones?), I'm aware there are several similar questions on this site (see here, here, here, here, and here) but they are either unanswered or the answers are unacceptable ("use fitXY", which does not preserve aspect ratio, or require specifying exact pixel width/height in the ImageView which is not a general purpose solution to the problem). It'd be nice to get a solid answer to this documented and out there.
Answering my own question in the hopes it helps someone else.
I found a simple functional answer here. The AspectRatioImageView class works where all my XML scaling attempts failed.
I have a Widescreen Image that i want to put into a horizontal scroll view, with it ftting the whole screen vertically(and letting me scroll horizontally) but it simply stays at half height and won't let me scale it higher (layout_height is set to "fill_parent").
I already thought about using the image in different source resolutions but i think i cannot cover all possible resolutions so that is not really an option i guess.
I also want to put buttons on specific locations onto that image and want them to move with the image if that is important.
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.