How To Add ImageView Border Android Studio

How To Add ImageView Border Android Studio

Information, Technology No Comments on How To Add ImageView Border Android Studio

Adding ImageView Border In Android Studio

Today, I wanted to write this quick to blurb to try to help out anytime who is having troubled adding a ImageView border in Android Studio.

There is more than one way that an ImageView border can be added in Android Studio, but I will show the most quickest and fastest way to implement it without creating an extra resources file.

Originally, I had tried creating an extra resources file and placing it into my drawable folder for the ImageView border effect, however, this method was not working for me for some reason. So, instead of wasting more time on something that should be so simple, I decided to look into another option and I more than happy now since all it takes is place 3 lines into my ImageView in the layout file in orded to get a border effect.

Keep in mind though that this trick only seems to work for ImageView as when I tried placing the same code onto a button, it just filled and changed the color of the background button, it did not created a border.

How to Add ImageView Border Android Studio?

In order for me to place a border onto an ImageView, I simply wrote the 3 lines of code below and placed that into my imageview in the layout.xml file.


With those 3 lines of code place directly into my ImageView, I got this result.

As you can see, the ImageView now has a black border around it with 5dp padding on each side. I am sure you can also attain this through other methods such as the creating an extra resource file and pointing to that, but that didn’t seem to work for me for some reason, so I decided to try this out and so far, so good!

Leave a comment


Back to Top