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
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.
A list view is an adapter view that does not know the details, such as type and contents, of the views it contains. Instead list view requests views on demand from a ListAdapter as needed, such as to display new views as the user scrolls up or down. In order to display items in the list, call setAdapter(android.
ListView uses Adapter classes which add the content from data source (such as string array, array, database etc) to ListView.
Android ListView is a ViewGroup that is used to display the list of items in multiple rows and contains an adapter that automatically inserts the items into the list. The main purpose of the adapter is to fetch data from an array or database and insert each item that placed into the list for the desired result.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With