How do you put a border around a ListView?
I would like to put a border around my listview that is a few pixes wide. I want it to to go around the entire listview piece. How can I do this? thanks
The other way to do it is to create a border resource that can then be reused, and it also means you won't need to create extra layout to implement it.
-
create a drawable resource
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" > <!-- use this for transparent --> <!-- <solid android:color="#00000000" /> --> <!-- use this for a background colour --> <solid android:color="#FFF" /> <stroke android:width="2dip" android:color="#FF0000" /> </shape>
-
then set it as the listview background
<ListView android:id="@id/android:list" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@drawable/border_ui" />
For this first take the LinearLayout and assign that linear layout with some color and take a list view in that linear layout. Set the android:layout_margin="10dp"
property for list view . That means on all 4 sides 10dp space will be left. This shown as the border of the list view.
Simplest way:
<ListView android:id="@+id/listView1" android:layout_width="match_parent" android:layout_height="0dp" android:divider="#FFCC00" android:dividerHeight="2dp" android:layout_weight="1" />