Resize an ImageButton - android

I know that the question has been asked a lot, but not this case.
How can I make the ImageButton area follows the size of the image source of the ImageButton (the blue rectangle)? I wont't set fixed values for the width and height.
Is that possible?
1- Normal condition. 2- When I scale the image
Another description of the problem

I think this is what you need android:adjustViewBounds="true"

Related

Android XML ImageView

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!

ImageView of width larger than the screen width

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"

ImageButton Stretching Background Image

I am trying to create an ImageButton with no border but I am running into an issue with the sizing of the image button.
Using Eclipse ADT I drag an ImageButton to the layout and select my background image. The image button appears as follows:
As you can see there is a border between the background image and the image button perimeter which I would like to get rid of. To do so, I set the padding property to 0dp. The image button now looks like this:
Finally, I set the scale type to fitXY:
Notice that the image is stretched and is no longer the size of the original image. (I want the ImageButton size to be exactly the same size as the background image.)
Here is a snapshot of all 3 images next to each other to make the difference more clear:
I have tried re-sizing the image, setting the max size properties, etc. but nothing seems to prevent the image button from stretching the background image.
How do I prevent the image from stretching like it is?
UPDATE
I also tried setting scale type to matrix but here is what happened:
Just set your image as android:background for button and set layout_height and layout_width for button to wrap_content
Maybe this might help, but I also know its best practice to make different sized images from android development.
https://developers.google.com/appengine/docs/java/images/overview
Use an ImageView instead and set it to be clickable. Set the scaleType to matrix (which will cause the ImageView to be as big as the image inside of it).
The problem with ImageButton is that it adds a background that causes padding, etc.
You can set
android:background="#null"

Something equivalent to scaleType in a Button

How can I use scaleType for an image in a button?
I am using a button with drawableTop (image with text below it). I have an image and I want it to fit the button boundries (currently it is too big to fit and resulting in truncated image)
There is no scaleType attribute for button so how can I do it?
Thank you
What you need is android nine-patch images to be used as button background.
There is a good tutorial here
Also look here Here

Image Draw9Patched is stretched on the wrong area

After Draw9Patching some image I had in my drawable folder, I want to make it have a certain height.
At start I have this picture :
Then, when I apply ScaleType to "fitXY" in order to "strech" my image, and when I define my height, it's incorrect :
The arrow on the bottom of my imageview get stretched, however I mentioned on my draw9patch not to stretch this area.
Do you have any explanation of this problem ?
Thanks in advance!
I'm pretty sure 9patches are meant to be used as backgrounds of Views, not as the source of an ImageView. If you set the background of a TextView to this 9patch, everything will work fine.

Categories

Resources