Search code examples
androidgraphicsnine-patch

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 callout Long callout

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


Solution

  • 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 here enter image description here