Reputation: 83
I am making a contacts app. I wish to list the contact name one after another. However, the result that I get is not satisfactory. The output of this xml is contact name was listed in a way that one contact name for each background. I have a very long space between each contact name.
Below is my xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/layout1"
android:background="@drawable/bg"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/contactTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="8dp"
android:textSize="20sp"
android:textColor="@android:color/black"
android:minHeight="?android:attr/listPreferredItemHeight"
android:gravity="center_vertical">
</TextView>
</LinearLayout>
The output looks like it lists one contact name for one background photo.
I wish to post the screenshot here but my reputation is too low. Any help would be very much appreciated.
Upvotes: 0
Views: 691
Reputation: 17401
If you want all items with same background set @drawable/bg
as the background of list view instead of one item of list view.
Try this:
You can post the layout that has a listview, but for now consider this list view which has android:background="@drawable/bg"
<ListView
android:id="@+id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/bg">
</ListView>
And layout for each item will not have any background
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/layout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/contactTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="8dp"
android:textSize="20sp"
android:textColor="@android:color/black"
android:minHeight="?android:attr/listPreferredItemHeight"
android:gravity="center_vertical">
</TextView>
</LinearLayout>
Upvotes: 1