Joop Joop - 1 month ago 4x
Android Question

Is there an easy way to show borders around Views and ViewGroups in the design tab of Android Studio for debugging and styling purposes?

I would like to see visually how much space each box takes with as little effort/changes to the code as possible.

I would like to know if it's possible to just put a line around the outer margins of the View or ViewGroup object.

Since it's just for debugging and styling I would like to also quickly turn it off, so I do rather make the changes to my code in one place so it's easy and quick to undo. Is this a default option I am missing? Somehow I expect this feature to exist already.

Here someone asks a different but slightly related question with not a nice answer for my case.

Here someone gives an answer on how to outline one View.
Border for an Image view in Android?


Code-wise you could follow the answer to the first link you posted and create a drawable with the name "developer_borders" or something similar and apply it to every view you wish to have its borders visible.

To easily remove it afterwards, you can right-click the directory of your project and click Replace in Path.... For Text to find you want to search for android:background="@drawable/developer_borders and for Replace with don't use anything. This will find every occurrence of what you are searching and replace it with an empty string.

There might be an easier option. Some devices have quite powerful Developer Options. "Show layout bounds" is what you want but take a look at the rest while you are at it, some are pretty awesome.