Nine-patch image shows strange behaviour? - android

I am creating an app in Android which implements Chat feature in it. I have 2 kind of chat bubbles - blue for other user and orange for logged in user. I am using Nine-patch images for these bubbles because the bubble can be stretched.
The text in the blue bubble is showing fine - right in the center(as shown in the figure below). But the text in the orange bubble is showing after some vertical gap from the upper border of the image. I can't figure out why this is happening. Both the bubbles have same properties and have been created following the same procedure. Please help. Thanks in advance.
Here is the orange chat bubble:

The problem is in the nine-patch.. the right hand border defines where the content goes and you have it starting just under the pointy part of the speech bubble. Continue the border up to where you want the content to start and it will work!
To clarify: the right and bottom borders define where the content can go, and the top and left borders define the area of the image that will be repeated when the image needs to be stretched.
Try this:

draw9 will stretch as what you want.
//your image width is too long. use this one for your reference.
//this image will work fine for me as I am using for left side.
your orange chat bubble is also fine if you put one dot on the right side above the arrow.

Related

Android Printing Custom Layout

I have a custom layout with a border for a receipt to be printed on A5 paper. I m able to get it to work but i m facing one strange issue for the text view which has borders only on the left and bottom side. As everybody uses, i have also used layer drawable as a background. On-screen it is displaying correctly i.e. have a border in the bottom and left. But in print out, i m getting a thin line on the top and right side of the view as well.
Adding screenshots for on-screen view and printed pdf.
How to set the text view border so i do not get thin lines on other sides where i have not set the border?

Create simple 9 patch image that keeps logo in centre

I am trying to create a simple 9-patch image that keeps the image in the centre.
The logo I am using is similar to this:
The stretchable regions would of course be the sides and the top. The static region would the be the logo itself.
The tool I am using is the following:
https://romannurik.github.io/AndroidAssetStudio/nine-patches.html#&sourceDensity=320&name=example
Unfortunately, no matter how much I try I just can't seem to get this right.
I can easily make the logo stay on the top right, but not in the centre.
How do I get it so the logo stays in the centre?
Can someone show me how to achieve my desired behaviour. A screenshot will be ideal!
It turns out it was not possible using that tool as you can only place 2 stretchable regions.
Instead I used the tool provided by the android sdk located at:
path-to-android-sdk/tools/lib/draw9patch.jar
The above tool allows you to state multiple stretchable regions.
You need 4 to achieve the centre behabiour.
One on either side of the top edge and one on either side of the left edge.

set up different clickable part image android

Im working with android about image and onclick listener. The purpose of my app is to monitor the area that user clicks on the screen. For example, I have a picture containing a rectangular and a circle. Assume that the color of the whole picture is brown(wood). So when I click on the rectangular, the color of rectangle will change to yellow. When I click on the one part of the picture, the color of that part will change its color, but other parts do not change. So, Im thinking about the solution for this app. Do I have to cut this picture separately and put them into the screen by using relative review? Or is there any other way to do this(Set up a coordination system)?
Yes you have to cut this picture separately and put them into the screen by using relative review. For example two ImageView with your backgound.
You can slse the image as recommeded by the other post, or overlay the image with a RelitiveLayout with specific sized buttons (background = #android/color/transparent)

How to 9-patch so icon always stick with centered text

Basically, I wanted to have a button where text and icon stay in the middle of the button at all times. The Button has match_parent width and center gravity. I tried to use drawableLeft but that put icon on the left most of the Button and not next to the text.
So I'm trying to create 9-patch image as shown in the image above. Basically, I want all the text to stay in blue box with the cyan rounded rectangle (icon) next to it. The stretchable area is in red. However I just can't make it as the content area always overlap the icon.
Is this possible with 9-patch? Or should I wrap Layout around the TextView and use that as a button instead?
By the way, the included image is just to show what I plan to do. The actual image will be in other colors and without all the red.
When you create a nine-patch image, you put some black lines on the right and bottom of the image. These lines define the region that will be use to place the content inside of your image.
Here is an example :
It will look like this :

Android: how to use the 9patch creator?

I am trying to create a stretchable scroll handle for my app.
The first image is the scrollhandle.9.png that I include in my app's resources.
The second image shows what this 9patch image looks like when used in my app.
Any advice on how to accomplish a stretchable scroll handle?
Edit: With help from posters, I was able to get an image that works. I added it below to help those who may find this in the future.
The area covered by the top and the left black line(dots) will be used while scaling your image. This area will be highlighted to you when you click the "show patch" option. You can see how the image scales by using the "Patch scale" option given in the draw9patch tool.
The area covered by the right and bottom lines(dots) will hold the content for the background.
Eg: You can define boundaries for the text inside 9 patch image for editor background. For your case you don't need right and bottom lines.
So for your case place two dots at the top corner and two dots at the left corner. Make sure patches doesn't fall in the arrow image of the scroll(if they do fall your arrow image will also get stretched) . Try putting the dots only in the left and top lines till you get the desired preview with "Patch scale" option.
If you use only one dot (instead of four) at the top and bottom left, and one at image top center, it should stretch the way you want it to.

Categories

Resources