Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I set a border around an image in Android?

Preferably, I'd like a somewhat fancy bevel . I'd like the picture to have some depth on it..so it doesn't look so plain and old-fashion :)

like image 878
TIMEX Avatar asked Dec 18 '22 02:12

TIMEX


2 Answers

You can perhaps do something with the 2D Canvas API, but I don't know enough about that to describe a process. Here's how you can try to do that with ordinary widgets...well, mostly ordinary...:

Step #1: Create a nine-patch PNG that has your "somewhat fancy bevel" and is designed to stretch around images.

Step #2: Set that nine-patch PNG as the background of the ImageView that has your image.

Step #3: Adjust the padding of the ImageView so that your bevel shows -- that'll depend on how wide you made the bevel effect.

It's possible you'll need to put the nine-patch PNG on a LinearLayout or something and have the ImageView in there (then use margins to allow the bevel to peek through), but I think you can do it without the extra widget.

like image 112
CommonsWare Avatar answered Dec 19 '22 14:12

CommonsWare


I would say that the easiest thing to do is to set nine-patch PNG as the background of your ImageView. This way the src would load the image, while background attribute would load the background 9.png image.

When creating 9.png for the background take care that you do not mark border lines as streatchable. Look at the image.

like image 34
sandalone Avatar answered Dec 19 '22 14:12

sandalone