Android–Create a ListView with rounded corners

In a previous post I showed how to create a custom multi-line ListView bound to an ArrayList. Let’s make it a little more visually appealing and give each item some rounded corners.

If you followed the previous how-to you wound up with something that looked like this:

image

To put each ListView item (name, address & phone) into its own rounded-corner box, create a new file in your res/drawable directory called border.xml, and paste in the following code:

<shape xmlns:android="http://schemas.android.com/apk/res/android" >
    <stroke android:width="1dp" android:color="#FFFFFF" />
    <padding android:left="5dp" android:top="5dp" android:right="5dp" android:bottom="5dp" />
    <corners android:radius="8dp" />
</shape>

Then, specify the background of your LinearLayout in custom_row_view.xml:

android:background="@drawable/border"

And that’s it:

image

Of course, you can mess with colors, padding etc. to get the look you want, and you can apply this to just about any object in your layout.

Technorati Tags:

Print | posted @ Monday, February 06, 2012 4:26 PM

Comments on this entry:

No comments posted yet.

Post A Comment
Title:
Name:
Email:
Website:
Comment:
Verification: