0

I have to make a layout where in the first row I have a heading and below it, there is listview. The heading should be placed left align and the listview should be match the total width. For this, I am using the following xml.

<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/splashContent"
    android:layout_width="wrap_content"
    android:layout_height="fill_parent"
    android:background="#7A0225"
    android:orientation="vertical" >
    <TableRow
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:gravity="top|left"
        android:layout_weight="0"   
        android:background="@drawable/search_bg_row1">
        <TextView
            android:id="@+id/pcomparetitle"
            android:layout_width="wrap_content"
            android:layout_height="fill_parent"
            android:paddingBottom="4dp"
            android:paddingLeft="10dip"
            android:paddingRight="0dip"
            android:paddingTop="10dp"
            android:text="Price Comparison for ISBN: "
            android:textColor="#FFFFFF"
            android:background="#00FF00"
            android:textSize="15sp"
            android:textStyle="bold" >
        </TextView>
    </TableRow>
    <TableRow
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_weight="1"
        android:gravity="center_vertical|left"
        android:background="@drawable/search_bg_row3">
        <ListView
            android:id="@+id/pricelist"
            android:background="#FF0000"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent">
        </ListView>
    </TableRow>
</TableLayout>

Now, the Listview is taking the width the same of the heading. As the heading is short in comparison with the width of higher resolution display, the listview is taking partial width. How to solve this problem?

Dalmas
  • 26,409
  • 9
  • 67
  • 80
dev_android
  • 8,698
  • 22
  • 91
  • 148
  • 1
    If you just want to set a header for your ListView, there is the `addHeaderView` method : http://stackoverflow.com/questions/2620177/android-adding-static-header-to-the-top-of-a-listactivity – Dalmas Dec 20 '11 at 13:18

1 Answers1

2

I think this is enough for u to display a textview and a list view below it:

 <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/splashContent"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#7A0225"
    android:orientation="vertical" >

        <TextView
            android:id="@+id/pcomparetitle"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Price Comparison for ISBN: "
            android:textColor="#FFFFFF"
            android:background="#00FF00"
            android:textSize="15sp"
            android:textStyle="bold" >
        </TextView>

        <ListView
            android:id="@+id/pricelist"
            android:background="#FF0000"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent">
        </ListView>
    </LinearLayout>
Seshu Vinay
  • 13,560
  • 9
  • 60
  • 109