Home > Android > Android practice – ListView With Round Corner

Android practice – ListView With Round Corner

1, Use the shape tag to create a drawable[listview_roundcorner_item.xml] with rounded corners. Like ,

</pre>
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
 android:shape="rectangle" >

<gradient
 android:angle="270"
 android:endColor="#E77A26"
 android:startColor="#E77A26" />

<corners
 android:bottomLeftRadius="8dp"
 android:bottomRightRadius="8dp"
 android:topLeftRadius="8dp"
 android:topRightRadius="8dp" />

</shape>
<pre>

2, There are two ways to implement it .

  • Add attribute to ListView

android:background="@drawable/listview_roundcorner_item"

  • Set background by sourcecode

listView.setBackgroundResource(R.drawable.listview_roundcorner_item);

3, Finally , if you run this example you would get the following effect.

About these ads
Categories: Android
  1. JJ
    November 4, 2012 at 7:47 pm

    Clean and simple example..

    Already new this, but found your blog by “accident”..

    Nice to see that this can be written down in a simple way. Too many complicated explanations out there..

    Thumbs up!

  2. N.Nagaganesh
    February 11, 2013 at 8:58 pm

    Big Thanks to you.

  1. No trackbacks yet.

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

%d bloggers like this: