androidandroid-layoutnine-patch

How to place text within the content area of a nine patch image?


A nine-patch image was set as a background image for a Textview, with text currently being aligned to the upper left of the TextView when the text should be located within the defined content area.

I've tried setting the constraints for which the stretch area and content area should be defined and it is displayed like this:

Nine Patch image

However, the text does not appear within the content area.

TextView with Nine-patch image background

What should be changed so that the text appeared within the nine-patch image's content area?


Solution

  • What worked for me: I just realized that if I run the app live on my Android device, the text indeed appears in the nine-patch content area, but not when viewing the layout in Android Studio. Could be an internal issue with Android Studio.