0

我遇到了 TableLayout 行高的问题。
如果

android:stretchColumns="1"

结果是
在此处输入图像描述
你可以看到它被剪切的最后一行的文本

如果我不指定stretchColumns结果是:
在此处输入图像描述
它现在显示的文本,但表格(黑色)变得非常大而没有内容。

这是代码:

<TableLayout
       android:id="@+id/my_table"
       android:layout_width="match_parent"
       android:layout_height="match_parent"
       android:stretchColumns="*"
       android:layout_marginLeft="15dp"
       android:layout_marginRight="15dp"/>


<TableRow xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/my_table_row"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:gravity="center_vertical"
    android:minHeight="30dp"
    android:weightSum="6" >

    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="0.4"
        android:gravity="center" >

        <ImageView
            android:id="@+id/column_one"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:contentDescription="@string/app_name" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="3.9"
        android:gravity="center_vertical|left" >   

        <TextView
            android:id="@+id/column_two"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textSize="18sp" >
        </TextView>
    </LinearLayout>

    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1.7"
        android:gravity="center_vertical|right" >

        <TextView
            android:id="@+id/column_three"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:ellipsize="marquee"
            android:focusable="true"
            android:focusableInTouchMode="true"
            android:marqueeRepeatLimit="marquee_forever"
            android:scrollHorizontally="true"
            android:singleLine="true"
            android:textSize="18sp" />
    </LinearLayout>

</TableRow>

我正在填充行并以编程方式添加到表中。

为什么会这样?

4

1 回答 1

2

我讨厌这种类型的解决方案,但是哦,好吧......我将它切换到 LinearLayout(表和行)而不是 TableLayout,但问题是一样的。不同之处在于,使用 LinearLayout,我只添加了一个“空行”,就实现了目标。使用 TableLayout 和 Rows 尝试了相同的方法,但没有运气。

@Francisco Corrales Morales

myLinearLayoutTable.addView((LinearLayout) inflater.inflate(R.layout.my_row, myLinearLayoutTable, false));
于 2013-04-30T14:11:19.267 回答