Wednesday, March 23, 2011

Creating a simple border with rounded corners for a layout or view

not the border in question..

Hi all, just thought I'd post this simple snippet that I've just found.
This allows you to simply add a border ( even with rounded corners!) to a layout or view.

All you need to do is create a new xml file somewhere in /res/drawable called 'the_border.xml'
with this or similar as the contents:

<shape xmlns:android=""> 
    <stroke android:width="1dp" android:color="#FFFFFF" /> 
    <padding android:left="7dp" android:top="13dp" 
            android:right="7dp" android:bottom="17dp" /> 
    <corners android:radius="4dp" /> 

You can then reference this as the background of an item in your layout like this (in xml)


or like this in code:


Nice eh?

1 comment: