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

1

9

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?

Deadradeadweight answered 4/4, 2013 at 1:35 Comment(1)
The key thing to remember is that the stretchable regions (defined by your black lines on the top and left sides) are stretched proportionally depending on their lengths. So as the accepted answer states, ensure they match lengths on the top side to make sure the "nub" stays centered. You can use the draw 9-patch tool to create your 9 patches from your raw resources and make sure they are stretching as you intend them. (BTW funny to see someone I actually know on here)Lanky
C
8

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

Catlee answered 4/4, 2013 at 1:43 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.