无法将TableLayout拉伸到屏幕宽度

时间:2010-03-14 00:28:02

标签: xml android user-interface

我已经尝试了几个小时不成功,只是简单地让TableLayout扩展到全屏。我已尝试使用stretchColumns,shrinkColumns(指定列索引或使用*)来命名它。 这几乎就像父元素(TableLayout)完全忽略了'android:layout_width =“fill_parent”'。

我在这里读过类似的问题,虽然他们还没有为我解决。 下面的XML有3行,表总是将包装缩小到内容的大小。

显然我太新了,无法发布图片(?)这是我正在处理的项目中呈现的XML。 http://www.dashiva.com/images/Capture.png

我在这里缺少什么,这非常令人沮丧!

<TableLayout
xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" android:stretchColumns="*">

<TableRow>
    <TextView android:id="@+id/AmountText" android:text="@string/general_amount" android:paddingRight="8dip" android:layout_gravity="center"></TextView>
    <TextView android:id="@+id/CardText" android:text="@string/general_card" android:paddingRight="8dip" android:layout_gravity="center"></TextView>
    <TextView android:text="@string/general_date" android:id="@+id/DateText" android:paddingRight="8dip" android:layout_gravity="center"></TextView>
    <TextView android:id="@+id/ErrorText" android:text="@string/general_error" android:paddingRight="8dip" android:layout_gravity="center"></TextView>
</TableRow>

<TableRow>
    <TextView android:text="Amount here..." android:id="@+id/AmountNum" android:paddingRight="8dip" android:layout_gravity="center"></TextView>
    <TextView android:id="@+id/CardNum" android:text="Num here..." android:paddingRight="8dip" android:layout_gravity="center"></TextView>
    <TextView android:text="date here..." android:id="@+id/DateDate" android:paddingRight="8dip" android:layout_gravity="center"></TextView>
    <TextView android:text="Code here..." android:id="@+id/ErrorCode" android:paddingRight="8dip" android:layout_gravity="center"></TextView>
</TableRow>

<TableRow>
    <ImageView android:id="@+id/cc_image" android:src="@drawable/mastercard" android:background="@drawable/row_bg2" android:layout_gravity="center" android:layout_weight="1"></ImageView>
    <TextView android:id="@+id/ResponseText" android:layout_span="4" android:text="Response text here..." android:textSize="18dip" android:layout_weight="1"></TextView>
</TableRow>

<ImageView android:layout_gravity="center_vertical" android:background="@drawable/gradient_bg" android:layout_height="3dip" android:layout_width="fill_parent"></ImageView>
</TableLayout>

3 个答案:

答案 0 :(得分:1)

嗯,我可以告诉你:

  1. 我删除了您的ImageView元素(因为我没有您的图片),TableLayout非常好地填充了屏幕的宽度。
  2. 您的上一次<TableRow>声明有五列(一列用于ImageView,四列用于TextView),而其他行有四列。
  3. 所以,我会尝试将android:layout_span="4"更改为android:layout_span="3",看看是否有帮助。

答案 1 :(得分:1)

如果未设置layout_weight,则拉伸也不起作用。这不是你的问题,但也许它可以帮助其他人来到这里。

(docs / guide / topics / ui / layout-objects.html说:“子视图可以指定整数权重值,然后视图组中的任何剩余空间按其声明权重的比例分配给子项。默认权重为零。)“

答案 2 :(得分:0)

好的,问题在于我以编程方式夸大了XML。 出于某种原因,我将它膨胀到一个视图然后将其添加到TableRow,然后将其添加到父视图。 删除中间步骤并将膨胀的视图添加到父元素可以解决问题。

谢谢,但我认为跨度是一个简单的计数,而不是从零开始。