Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to make a 9-patch drawable for a callout graphic?

I'm trying to make a callout graphic in Android. I'm not married to the idea of using a 9-patch-drawable, but I think it's the right way to go. I'm essentially trying to make a button with a little nub at the bottom. I'd like the nub to be centered regardless of the size of the content. Here are some example graphics showing what look I'm going for:

Short calloutLong callout

Is there a way to keep the bottom little nub centered using a 9-patch drawable?

like image 535
Zach Rattner Avatar asked Apr 04 '13 01:04

Zach Rattner


People also ask

How do I create a 9 patch image?

In Android Studio, right-click the PNG image you'd like to create a NinePatch image from, then click Create 9-patch file. Type a file name for your NinePatch image, and click OK. Your image will be created with the . 9.

What is a 9 patch?

A 9 patch image is a regular png (. PNG) image which is needful for android app developers where they require to wrap any content within a background image without pixelating the background image.


1 Answers

Is there a way to keep the bottom little nub centered using a 9-patch drawable?

Yes, absolutely. As a matter of fact, a 9-patch is definitely the right way to go for this.

Just make your 9-patch have two stretchable regions: one to the left on the nub and one to the right. You'll want to make sure both regions are equally 'large'. In other words: the two horizontal black lines that define the horizontally stretchable regions should have equal length - that will make the nub stay in the horizontal center.

Here's are two examples of images that are part of the mapview-balloons library:

enter image description hereenter image description here

like image 169
MH. Avatar answered Oct 09 '22 09:10

MH.