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"
Related
Is this possible, have anyone done anything close to this? I saw this behaviour in an ios app and need to reproduce it, basically the image is full size on the X axis and it can move up and down through the Y axis inside an Imageview, I tried doing this with an Imageview inside a FrameLayout without success, the Image is always cropped to the max size of the Imageview which is relative to its parent (FrameLayout). Any help is welcome.
I guess you could just write your own class. Intercept the touch events, monitor the vertical offset and redraw the image with this vertical offset.
I've been trying to find an answer to this all of last evening with no luck so I decided to come ask here. I just started getting into front end dev for Android apps and I'm trying to do something really simple that just doesn't work. All I want to do is add an image on the screen and be able to resize it EXACTLY what size I want regardless of proportions. This is the code I'm currently using inside a relative layout:
<ImageView
android:layout_width="400dp"
android:layout_height="200dp"
android:id="#+id/imageView"
android:scaleType="fitXY"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:src="#drawable/statsus_logo" />
My image is a horizontal rectangle. When I first add it, it shows up inside a small square centered with a bit of padding all around. When I make the width 400dp that square appears to strech almost 100% across the screen however the logo stays the EXACT same size, centered vertically and horizontally inside this imageview container. When I increase the height of the imageview, the logo increases its size but almost as if it was taking the height and using it as a width. I feel like what its trying to do right now is use the height as its width and the only time when its width is the value i put in, is if the height is also the same value and even then there's some extra unwanted padding.
Again, all I want is for this damn image to be the size I tell it to, so if I want it 5dp wide and 100dp tall, it does just that. Can anyone please help? Thank you very much in advance.
Try to add this attribute to your imageview
android:scaleType="fitXY"
Scale type reference
android:scaleType="fitXY" is the way to scale your image however you want without keeping your proportions however my issue was a little bit different... I'm using android studio and for some reason the settings I was using to "add a new image asset" was making my image act the way I described it above... if I just add an image manually by just click and dragging into the folder, then the image works the way I want it... so long story short, the issue was with how I added my new image asset
thanks to everyone for all of your answers and help!
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 am making a lot of ImageButtons where the image aspect does not matter. That is, I do not care if it is stretched. They are invisible buttons to go on top of a background.
Is there an easy way to layout and stretch my ImageButtons through the graphical editor? I do not want to have to test out each possible padding in my xml. I just want to stretch the sides of the images as though it were an Office Word.
Ask if clarification is needed, please.
I'm not really sure to understand your question, but you can use android:scaleType="fitXY" to stretch your images, and android:adjustViewBounds="true" to have them adjust their bounds due to scaling.
I'm not 100% sure about your question neither. If you meant you want to do it in IDE, eclipse allows you to define the button with dragging.
I have 2 PageViewers with 2 series of pictures each. Initially they were one close to another, but then I decided to make them overlap. To do that, I increased one's height with, let's say, y.
I want the overlapping to be visible only for the images with bigger height(they're PNGs), so the ones with the initial ViewPager height would look just like before the resizing
So, once I applied the y height, I saw that a gap appeared in the resized pageviewer, making the image decalate with y px. This somewhat seems normal, but ruins the mechanism, because I want the starting point of any image to be the upper-left corner of the pageviewer. I tried and researched all the layout attributes & pageviewer methods for something to help me set the starting point but I kinda went out of ideas.
You can try this:
android:layout_alignParentTop="true" to make the image to be the upper-left corner of the pageviewer.
For imageView we can set this property:
android:scaleType="fitXY"