Проблема размещения в макете - относительная ширина в процентах с использованием веса

Я пытаюсь назначить относительную ширину столбцам в ListView, который находится в TabHost, используя layout_weight, как было предложено здесь:

<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
  android:id="@android:id/tabhost"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent">
  <LinearLayout
     android:orientation="vertical"
     android:layout_width="fill_parent"
     android:layout_height="fill_parent">
     <TabWidget android:id="@android:id/tabs"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"/>
        <FrameLayout android:id="@android:id/tabcontent"
           android:layout_width="fill_parent"
           android:layout_height="fill_parent">
           <TableLayout  
              android:id="@+id/triplist" 
              android:layout_width="fill_parent"
              android:layout_height="wrap_content"
              android:paddingTop="4px">
              <TableRow>
                 <ListView android:id="@+id/triplistview"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"/>
              </TableRow>
              <TableRow>
                 <Button android:id="@+id/newtripbutton"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="Add Trip"/>
              </TableRow>
[other tabs ...]

В моем определении строки есть 4 столбца, размер которых я бы хотел изменить следующим образом:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
   android:layout_width="fill_parent"
   android:layout_height="wrap_content"
   android:orientation="horizontal"
   android:weightSum="1.0"
   android:padding="4px">   
   <TextView android:id="@+id/rowtripdate"
      android:layout_weight=".2"
      android:layout_width="0dip"
      android:layout_height="wrap_content"
      android:inputType="date"/>
   <TextView android:id="@+id/rowodostart"
      android:layout_weight=".2"
      android:layout_width="0dip"
      android:layout_height="wrap_content"/>
   <TextView android:id="@+id/rowodoend"
      android:layout_weight=".2"
      android:layout_width="0dip"
      android:layout_height="wrap_content"/>
   <TextView android:id="@+id/rowcomment"
      android:layout_weight=".4"
      android:layout_width="0dip"
      android:layout_height="wrap_content">

К сожалению, кажется, что нужно разместить все столбцы в том месте, которое занимает кнопка, а не на ширине экрана. Или, может быть, есть другое ограничение, которое я не понимаю. Буду признателен за вашу помощь.

alt text
(источник: heeroz.com)

Ответы

Ответ 1

Я думаю, что я забыл это свойство для элемента TableLayout:

android:stretchColumns="0"

Теперь он работает.

Ответ 2

Я не вижу ничего явно неправильного в том, что вы там показываете. Чтобы получить лучшее представление о том, что происходит, вы можете попробовать просмотрщик иерархии. Он поставляется с SDK. Он визуализирует для вас, сколько места занимает каждый из "скрытых" слоев, поэтому вы можете выяснить, какой из них решил только быть большим.