Say we got this button in a layout file, say app/res/layout/activity_main.xml:
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:background="@drawable/test"
android:text="ok" />
Also say that @drawable/test is an SVG file (vector image) that gives a unique shape for the button as follows:
The problem that I have is that when the text android:text="sadfsdafsadfsadfsadfsdfsdafsdf" is long, the button's shape gets ruined as follows:
As the button is stretched horizontally, I want only to stretch the button from the middle, without harming its shape on the sides.
This is the desired outcome (trying to achieve it, but so far it failed):
I heard of 9-patch files, but sadly they only work for bitmaps. About vector files: how can we maintain their shapes when scaled?



This can be achieved by trimming stroked path on your vector drawable.
More information is in Trimming stroked paths.
Example: