From time to time, I find myself wanting to do something in Android… and finding that I can’t get there from where I currently happen to find myself.
Today that something was “draw a border around an bitmap.”
My eventual solution was to do the following:
- Create an ImageView and wrap it inside a LinearLayout.
- Create a solid bitmap of the color that I want the border to be (using Paint and Canvas) and set it as the background for the LinearLayout, making sure that the size of this bitmap was 2 pixels longer and wider than the bitmap that I wished to border upon.
- Put the bitmap that I want to display in the ImageView, and make sure I have the gravity of both the ImageView and LinearLayout set to “center_horizontal | center_vertical“.
The solution, while not as simple as say setting an attribute named “border“, is workable enough.
I’ll include sample code over the weekend.
For now, it’s late Friday evening and time to do something relaxing.