2010-05-26 70 views
13

我試圖分配相對寬度的列在ListView是在TabHost,使用layout_weight百分比相對寬度的建議​​:Android的佈局問題 - 使用重量

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

不幸的是,它似乎想所有列融入空間的b utton佔據,而不是屏幕的寬度。或者,也許還有另一個我不明白的限制。我會很感激你的幫助。

alt text http://heeroz.com/layoutprob.png

回答

11

我想我忘了這個屬性爲TableLayout元素:

android:stretchColumns="0" 

這似乎是現在的工作。

+7

我會從px更改爲在您的佈局中下降以支持不同的屏幕分辨率。 – 2010-05-26 20:53:01

1

我看不出有什麼明顯的錯誤在你所展示那裏。爲了更好地瞭解正在發生的事情,您可以嘗試heirarchy viewer。它隨SDK提供。它會爲你展示每個「隱藏」圖層佔用了多少空間,因此你可以確定哪一個只有那麼大。

+0

感謝您的提示。我不知道這個工具。我發現ListView(136px)不會填充表格行(480px)的整個寬度,但爲什麼是一個不同的問題。 136px也恰好是按鈕的寬度。 – cdonner 2010-05-26 17:31:37