TableRow span not working for dynamically added rows

╄→尐↘猪︶ㄣ 提交于 2019-12-01 17:52:41

OK, I found the solution. It was simply to drop the TableRow tag for the row that I wanted to span across the table.

table_span_row.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_height="wrap_content" android:layout_width="fill_parent"
    android:background="#FF333333">
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content"
    android:layout_weight="1" android:text="This should span on the whole row" />
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content"
    android:text="... and now it does" />
</LinearLayout>

I do not know what will happen if I had 3 columns instead and wanted to span one of the cells on two of them :)

May be it will help to somebody. Even this question was more than 2 years I see the same bug right now. That is, rowSpanLayout.span = 2; doesn't work. But in xml layout_span it works. I found the workable solution: 1. create the layour xml file injection with layout properties:

 <TableLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:visibility="gone">
     <TableRow 
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:visibility="gone">
          <TextView
                android:id="@+id/check1"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_span="3"
                android:text="TextView" />
     </TableRow>
     </TableLayout>
  1. Get Layout properties from this layout element:
TableRow.LayoutParams blp;
blp = (TableRow.LayoutParams)check1.getLayoutParams();
blp.width = 100;
blp.height = 50;
TextView tw = new TextView(this);
tw.setTextSize(tsEL);
tw.setLayoutParams(blp);
tw.setText(R.string.empty);
tr.addView(tw);

It works.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!