Leang Socheat
Leang Socheat

Reputation: 1174

How to create layout with specify border line width?

Hi all from junior android. Any idea to create layout same as image above?. thank you. enter image description here

Upvotes: 0

Views: 166

Answers (1)

Ariles
Ariles

Reputation: 333

I may have an idea.

You can create a 9-Patch file and use it as a background of i.g: a FrameLayout.

  1. Create a png image and put it in your drawable directory
  2. Right-click the png file in Android Studio and choose "create 9-patch file"
  3. Double click the resulting file to open the editor

Now, you can use the editor to specify which parts of the image will be stretchable.

I created a quick test file that looks like what you want to achieve (minus some tweaks). You can see on the right side how it adapts when stretched.

NB: All the transparent space should be reduces to a 1px height/width, it will be stretched anyway. Only keep the black parts to scale. This way, you'll be able to adapt to smaller layout dimensions. If you need margins, it may be more flexible to add them in your xml layout.

Good luck !

enter image description here

Upvotes: 1

Related Questions