javaandroidxmlbackgroundnine-patch

How do I make a horizontally stretchable background in android


I want to make a button background like this

enter image description here

So that when the content gets longer the background only gets stretched form the central region and the circular sides stay CIRCULAR.

enter image description here

I tried to make a 9-patch without a vertical stretch region but the circular sides went oval like in different sizes as you can see in the picture below.

enter image description here

when I specify a vertical stretch region in the center, the background becomes like this which I don't want it to. this is an square with rounded corners.

enter image description here

I also have to say that this background is basically a pink border which has a pink drop shadow both on the inside and the outside. I couldn't find a way to implement this with android drawable as there is no efficient way to have a good shadow effect using it

I can't think of a clean solution for doing so. please help me.


Solution

  • Alright, I just made a custom view that extends FrameLayout and it has a customizable colored shadow and stroke.

    You can also use it to draw an inner background in the center.

    enter image description here enter image description here

    you can add it in your project from my GitHub page.

    https://github.com/mr-sarsarabi/NeonLightBackgroundLayout