Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android ListView items not filling the width

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>
like image 971
KousiK Avatar asked Dec 03 '13 08:12

KousiK


1 Answers

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.

like image 159
Infinite Recursion Avatar answered Oct 17 '22 05:10

Infinite Recursion