Image Draw9Patched is stretched on the wrong area - android

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.

Related

Android - Fit image in a circle button

Main problem:
I want to put my squared picture (or any other picture) in a rounded view (as a button).
What I tried
Created a circle drawable and set it as the background of the ImageView. Then set my image as src.
Used com.github.markushi:circlebutton
Results:
In both cases, the result is
I looked a lot on the net and the only solutions I found were the two listed above. I can't really figure out how to crop my Image to fit the central part of my circle.
I am looking for one solution between:
Image resized in the center of the button (not touching the border)
Image cut to not go outside circle borders.
Something like this:
For fitting image into circle button you can try following ways:
android:scaleType="centerInside"
and the other one is
android:scaleType="fitCenter"
inside ImageView and you are good to go.

Android - creating background image

I'm new to android programming and I was wondering about how to get a background image (ImageView) show a drawable with a correct size.
Let me explain well, let's imagine we have this image:
I want this image to get shown with this aspect ratio on all screens.
Since I don't want the image to get stretched, I would like to set manually how my image gets shown, maybe by modifying its scale with thirdy part software.
the problem with this image is that, in portrait mode, it's not guaranteed to see the ball, and so I want to crop the part of my image so that the ball gets shown on the bottom-right edge.
I know that I have to import my drawable for all resolutions, but simply importing does not help... Any suggestions?
EDIT:
I'm facing this problem with dynamic background ImageView, so I'm not going to user xml layout files.
Using scaleType attribute doesn't help for this, or at least not just by setting its value.

9patch images stretching incorrectly

(The black lines are not visible so I just made a replica of it in photoshop and enhanced the black lines for you people to understand. )
( The black lines are photoshopped. JUST so they look a bit visible here. )
Suppose, this is the 9patch image, i have broadened the 9patch black line in photoshop so its clearly visible.
This is how it is going to stretch. The logo remain in its original dimensions, only the blue space will stretch.
In the 9patch software, the X and Y coordinate results were perfect and they stretch the way they should.
However, when I insert this in my xml code, I get this result.
WHY is the logo part stretching ?
WHATEVER the dimensions of the layout may be, the logo should be in its right size , while the space around it SHOULD adjust , but its not happening so.
Edit::
The images in the jar preview fine, but when I actually use that resource in some layout, I get the incorrectly rendered result.
The xml code for the button :
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/button_normal" />
You do it wrong, To make a 9patch using photoshop:
1- add a new transparent 1-pixel in each image side (left, right, top and bottom)
2- draw the scaling and content in that transparent pixel (black color #000000), not over the image content it self.
3- save it as your_image_name.9.png
This is my version: logo.9.png
As you can see, it works just perfectly
Make sure you put it in the /res/drawable folder and it ends in .9.png

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"

Background in android layout is stretched

I put a background image to my Relative layout using android:background="#drawable/rajat2", where rajat2 is an image in all the drawable folders.
It sets the background to my layout but the background comes stretched to the whole screen.
I've tried putting the wallpaper through java code too but it still behaves the same!
If your drawable size is not exactly the screen size, the background will be stretched to the entire screen size. Consider creating the drawable for each type of screen size so it doesn't appear stretched.
If you don't want the image to take up the entire screen size, consider using an ImageView instead, and placing that inside your layout.
use draw9patch for the background image. it well help you.
If You are developing an application then set the layout width and height as match parent
and use 9 patch image for more exact value what you want

Categories

Resources