Android ширина таблицы расположения таблицы - PullRequest
0 голосов
/ 20 декабря 2011

Я должен сделать макет, где в первом ряду у меня есть заголовок, а под ним - список. Заголовок должен быть выровнен по левому краю, а список должен соответствовать общей ширине. Для этого я использую следующий 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>

Теперь Listview принимает ширину, равную ширине заголовка. Поскольку заголовок является коротким по сравнению с шириной дисплея с более высоким разрешением, представление списка принимает частичную ширину. Как решить эту проблему?

1 Ответ

2 голосов
/ 20 декабря 2011

Я думаю, этого достаточно для отображения textview и list view под ним:

 <?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>
...