Android Listview With Rounded Corners

To create a listview with rounded corners create a shape in xml.

Create roundedcorner.xml in the res/drawable

<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
 android:shape="rectangle" >
<gradient
   android:angle="90"
   android:endColor="#C0C0C0"
   android:startColor="#808080" />
<corners
   android:bottomLeftRadius="7dp"
   android:bottomRightRadius="7dp"
   android:topLeftRadius="7dp"
   android:topRightRadius="7dp" />
<stroke
   android:width="1px"
   android:color="#000000" />
</shape>

You can create a gradient, how much each corner radius should be and a stroke. In java set your listview.

listView.setBackgroundResource(R.drawable.roundedcorner);
Posted in Android, Tips and Tricks Tagged with: , , ,