Android ListView items not filling the width
Asked Answered
R

3

15

I have a ListView and the rows I am filling with another xml layout but the width of the ListView rows are not filling the listview width.I have searched everywhere and the answer I got is making the width fill_parent,but its not working for me...

Kindly help.... thanks in advance... here are codes:

row.xml

 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/ic_list_bg" >

<TextView
    android:id="@+id/textView01"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center_vertical|center_horizontal"
    android:layout_marginLeft="5dp"
    android:text="@string/_01_"
    android:textAppearance="?android:attr/textAppearanceMedium"
    android:textColor="@color/white"
    android:textSize="15sp" />

<TextView
    android:id="@+id/textView02"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center_horizontal|center_vertical"
    android:layout_marginLeft="5dp"
    android:text="@string/_interval_1_"
    android:textAppearance="?android:attr/textAppearanceMedium"
    android:textColor="@color/light_yellow"
    android:textSize="15sp" />

<TextView
    android:id="@+id/textView03"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center_vertical|center_horizontal"
    android:layout_marginLeft="5dp"
    android:text="@string/_00_00_05"
    android:textAppearance="?android:attr/textAppearanceMedium"
    android:textColor="@color/white"
    android:textSize="15sp" />

</LinearLayout>

ListView.xml

  <LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center_horizontal"
    android:layout_marginLeft="15dp"
    android:layout_marginRight="15dp"
    android:layout_marginTop="@dimen/item_spacing" >

    <ListView
        android:id="@+id/listViewIntervalDetails"
        android:layout_width="fill_parent"
        android:layout_height="150dp"
        android:layout_gravity="center_horizontal"
        android:background="@drawable/ic_interval_list_bg"
        android:cacheColorHint="#00000000"
        android:divider="#b5b5b5"
        android:dividerHeight="1dp"
        android:longClickable="true"
        android:padding="2dp" >
    </ListView>
</LinearLayout>
Rephrase answered 3/12, 2013 at 8:16 Comment(0)
H
27

In ListView.xml, change width of the LinearLayout to fill_parent.

Since the LinearLayout is the parent of the ListView, and it's width is wrap_content, so the ListView's width also gets same width as it's parent.

Hollishollister answered 3/12, 2013 at 8:23 Comment(0)
D
3

For those like me who are using a RelativeLayout, try this adding

    android:layout_alignParentEnd="true"

To your ListView (in ListView.xml in this case).

Dodeca answered 13/7, 2016 at 13:18 Comment(0)
A
0

Try this..

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" 
    android:background="@drawable/ic_list_bg" >

    <TextView
        android:id="@+id/textView01"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginLeft="5dp"
        android:layout_weight="1"
        android:gravity="center"
        android:text="@string/_01_"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:textColor="@color/white"
        android:textSize="15sp" />

    <TextView
        android:id="@+id/textView02"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginLeft="5dp"
        android:layout_weight="1"
        android:ravity="center"
        android:text="@string/_interval_1_"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:textColor="@color/light_yellow"
        android:textSize="15sp" />

    <TextView
        android:id="@+id/textView03"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginLeft="5dp"
        android:layout_weight="1"
        android:gravity="center"
        android:text="@string/_00_00_05"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:textColor="@color/white"
        android:textSize="15sp" />

</LinearLayout>
Ahmed answered 3/12, 2013 at 8:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.