Yeah, Yeah – I Didn’t Forget

Yeah, Yeah – I Didn’t Forget

A few weeks back I was lamenting the fact that Android doesn’t give you an easy way to simply draw a border around a picture.

But here is at least a workable way to do it in your layout files: enclose your images in a layout element (linear, relative, or absolute); give the enclosing layout element a background color; and place your image smack dab in the center of the layout. Done and done.

Like this (image with a red border 2 device independent pixels wide):

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="42dip"
android:layout_height="42dip"
android:gravity="center_vertical|center_horizontal"
android:background="#ffff0000"
>
<ImageView
android:id="@+id/photobitmap"
android:layout_width="38dip"
android:layout_height="38dip"
android:scaleType="fitXY"
android:layout_gravity="center_vertical|center_horizontal"
android:src="@drawable/placeholder_business_image" />
</LinearLayout>

Not anywhere near as simple as it needs to be (jeebus – how about just setting a bordered property, for crying out loud) – but workable enough for gubmint work.

Advertisements

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s