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.
Related
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'm implementing an animation which displays scrolling image. I need to display a image in its original size even if the width is more than the screen width and then have to animate it.
Please tell me how to place image like that.
Check out the different scaletypes here: http://bon-app-etit.blogspot.be/2014/01/imageview-scaletypes.html
I think you'll need android:scaleType="centerCrop"
There are couple of things you can do and it depends on the behavior you want to implement. A quick two solutions are:
You can use ScrollView with your image in it and by touching it you can move it left or right. Example solution you can find here: Displaying an image larger than the device's screen
You can use absolute layout (although this layout is already deprecated) and place your image in it. Make the layout width and height be the same as your image.
The animation can be done with many ways:
1. On touche event handling
2. Fling with scroller or gesture detector
3. Accelerometer tilt
Hope it directs you to the right solution.
Try using scaleType in ur imageview xml,
android:scaleType="fitXY"
I have some problems resizing ImageViews and ImageButtons.
Let's say that I have a Layout that has a rectangular shape (I don't want to know if it is a horizontal or vertical rectangle) and a ImageButton that contains a transparent background and as ImageResource a square image.
I want to keep the button square, so I use setScaleType(ScaleType.FIT_CENTER) to stretch the button. It works well.
The problems come when the button needs to be REDUCED to fit the rectangular layout, instead of stretched: in that case, the image is reduced correctly, but the space reserved in the layout is the one that would be reserved by the image if I hade made it crop.
This is what I think that happens:
the image is put in the layout
the space in the layout is reserved
AFTER THIS the image is resized
if the space asked is increased, the layout is enlarged, otherwise nothing is done
as a consequence in the layout the image results rounded by A LOT of empty space if the image needed to be reduced.
The classical problem is: I have a layout that should contain one row with - say - six square buttons. IF the button size is larger than the height of the Horizontal LinearLayout, the buttons end to be distantiated with a lot of empty space, instead of touching them.
I tried using fixed sizes for the images, to force them resize before putting them in the layout, but this is not a solution for me. First of all I want it to be dynamic (ie: the layout could change size during the app lifetime and the images should follow that). Second of all, when I put the image into the layout it can easily happen that the layout is not set yet and its size returns zero.
Can anyone help me?
Thank you.
Just add the attribute
android:adjustViewBounds="true"
to your image view element in your layout. You can have a look to the post Unwanted padding around an ImageView
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.
I have an Android Gallery setup on a layout with both the width and height set to Fill_Parent. This works great for smaller screens, but as the display size grows into the tablet sizes, the Gallery stretches to a layout that is taller than it is wide. At this point, there are no more side images on it - that is, just the main selected image is visible. I want to have at least a small amount of the side images visible so the user knows the view is scrollable.
Does anybody know how I can do this?
Is it possible to maintain an aspect ratio while still using fill_parent? Is it possible to set the Gallery view to show a certain amount of the side images? etc?
Thanks!
The Gallery class is pretty limited and personally I tend not to use it. Have you considered using a ViewPager instead?
AFAIK, If you are using
android.widget.Gallery
then the implement a custom adapter to the view, and set a layout wrapped to each items inside the gallery view. If you still don't understand what I just said, I would try to generate some reference code.