Show/Add rounded corner border around listview in android

How to set rounded corner border to whole list view using XML layout file.

Here in this tutorial we are creating list view with seven list items and adding rounded corners border on listview using XML layout file and setting up that layout file as background of list view. So here is the complete step by step tutorial for Show/Add rounded corner border around listview in android.

android-project-download-code-button

How to Show/Add rounded corner border around listview in android.

Code for MainActivity.java file.

 package com.addroundedcornerborderaroundlistview_android_examples.com;
import android.app.Activity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.ListView;


public class MainActivity extends Activity {

 ListView listView;
 String[] listValue = new String[] {
 "ONE",
 "TWO",
 "THREE",
 "FOUR",
 "FIVE",
 "SIX",
 "SEVEN"};
 
 @Override
 protected void onCreate(Bundle savedInstanceState) 
 {
 super.onCreate(savedInstanceState);
 
 setContentView(R.layout.activity_main);
 
 listView = (ListView)findViewById(R.id.listView1);
 
 ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_2, android.R.id.text1, listValue);
 
 listView.setAdapter(adapter); 
 }

}

Code for activity_main.xml layout file.

 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
 xmlns:tools="http://schemas.android.com/tools"
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 android:paddingBottom="@dimen/activity_vertical_margin"
 android:paddingLeft="@dimen/activity_horizontal_margin"
 android:paddingRight="@dimen/activity_horizontal_margin"
 android:paddingTop="@dimen/activity_vertical_margin"
 tools:context="com.addroundedcornerborderaroundlistview_android_examples.com.MainActivity" >

 <ListView
 android:id="@+id/listView1"
 android:layout_width="match_parent"
 android:layout_height="wrap_content"
 android:layout_alignParentTop="true"
 android:layout_centerHorizontal="true"
 android:background="@layout/rounded_corner_border" >
 </ListView>

</RelativeLayout>

Code for rounded_corner_border.xml file.

 <selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
 <shape android:shape="rectangle">
 <solid android:color="#ffffff"/>
 <corners android:radius="20dp" />
 <stroke
 android:width="2dp"
 android:color="#3bbdfa"
 />
 </shape>
</item>
</selector>

Screenshot:

Show/Add rounded corner border around listview in androidClick here to download Show/Add rounded corner border around listview in android project with source code.

Leave a Reply

Your email address will not be published. Required fields are marked *