How to set border around image in Android?

Preferably, I would like a little bizarre bevel. I would like the picture to have some depth, and it doesn’t look so simple and old-fashioned :)

+4
source share
2 answers

You can do something using the 2D Canvas API, but I don't know enough about this to describe the process. Here, as you can try to do this with ordinary widgets ... well, mostly ordinary ...:

Step # 1: Create a PNG with nine patches, which has its own “somewhat fancy bevel” and is designed to stretch images.

Step # 2: set this PNG with nine patches as the background of the ImageView that has your image.

Step # 3: Adjust the indentation of the ImageView so that your bevel is shown - this will depend on how wide the bevel effect was.

You may need to put PNG with nine patches on LinearLayout or something similar and there will be an ImageView (then use the fields to let the bevel peep), but I think you can do this without an additional widget.

+7
source

I would say that the easiest way is to set nine PNGs as the background of your ImageView. This way src will load the image, while the background attribute will load the 9.png background image.

When creating 9.png for the background, make sure that you do not mark the border lines as a slice. Look at the image.

+5
source

Source: https://habr.com/ru/post/1301556/


All Articles