1

Ok I have a TableView, in which I'm inserting rows programatically. My Table looks following:

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:isScrollContainer="true"
    >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">
        <TableLayout
            android:id="@+id/tableLayout"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_marginTop="20dp"
            android:stretchColumns="0,1,2,3,4">

        </TableLayout>

    </LinearLayout>
</ScrollView>

And I'm adding rows in such way:

     public void addRow () {

        int rowHeight = 200;

        final TableRow tbrow = new TableRow(this);
        final TextView t1v = getTextView("10 ");
        tbrow.addView(t1v);
        t1v.requestLayout();
        t1v.getLayoutParams().height = rowHeight;

        final TextView t2v = getTextView("3");
        tbrow.addView(t2v);
        t2v.requestLayout();
        t2v.getLayoutParams().height = rowHeight;

        final TextView t3v = getTextView("5");
        tbrow.addView(t3v);
        t3v.requestLayout();
        t3v.getLayoutParams().height = rowHeight;

        final TextView t4v = getTextView("5");
        tbrow.addView(t4v);
        t4v.requestLayout();
        t4v.getLayoutParams().height = rowHeight;

        final TextView t5v = getTextView("from 1005\nto 1009");
        tbrow.addView(t5v);
        t5v.requestLayout();
        t5v.getLayoutParams().height = rowHeight;

        tl.addView(tbrow);
    }

    private TextView getTextView(String text)
    {
        TextView textView = new TextView(this);
        textView.setText(text);
        textView.setTextColor(Color.BLACK);
        textView.setGravity(Gravity.CENTER);
        textView.setBackground(gd3);
        return textView;
    }

And the problem is now my table looks corrupted:

enter image description here

What I've tried is as suggested in this post to set on my tableLayout:

setColumnShrinkable(4,true);

However that doesn't work.

You help will be highly appreciated.

Community
  • 1
  • 1
hris.to
  • 6,235
  • 3
  • 46
  • 55
  • Have you tried reducing the text size of last column ? And also the post which you've linked in this question suggests that you put in your xml `android:shrinkColumns="*"` OR `android:shrinkColumns="0"` to your `TableLayout` – Sharp Edge Sep 01 '15 at 07:07
  • I've tried setting `shrinkColumns` inside xml and the result is exactly the same. When one of the textViews comes to second line it gives that weird top padding. – hris.to Sep 01 '15 at 07:19

0 Answers0