Question

I'm having a problem with TableLayout row height.
If

android:stretchColumns="1"

the result is
enter image description here
as you can see the text from the last row it's cut

if I don't specify stretchColumns the result is:
enter image description here
the text it's now showing but the table (black) gets extremely big without content.

Here's the code:

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

I'm populating the rows and adding to the table programmatically.

Why is this happening?

Was it helpful?

Solution

I hate this type of solutions but oh well... Instead of TableLayout I switch it to LinearLayout (both Table and Row) but the problem was the same. The difference is that with LinearLayout I just added one "empty row" and I achieve the goal. Tried the same approach with TableLayout and Rows but with no luck.

@Francisco Corrales Morales

myLinearLayoutTable.addView((LinearLayout) inflater.inflate(R.layout.my_row, myLinearLayoutTable, false));
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top