Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 429
Androider Avatar asked Feb 21 '11 12:02

Androider


People also ask

How to add border in ListView?

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.

What do you mean by ListView?

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.

What does ListView uses to place each item?

ListView uses Adapter classes which add the content from data source (such as string array, array, database etc) to ListView.

What is the use of ListView explain list view with example?

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.


2 Answers

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.

  1. 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> 
  2. 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" /> 
like image 86
Ben Neill Avatar answered Sep 23 '22 09:09

Ben Neill


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.

like image 22
Pinki Avatar answered Sep 21 '22 09:09

Pinki