Android Bordered Bitmaps

Android Bordered Bitmaps

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:

  1. Create an ImageView and wrap it inside a LinearLayout.
  2. 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.
  3. 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.

One thought on “Android Bordered Bitmaps

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s