java / android: table 布局 - 特定列的可见性

java / android: table layout - visibility of specific column

我动态创建了一个 table 布局。 现在,如果屏幕是横向或纵向,我想更改特定列的可见性。 这可以用我的代码实现吗?

感谢您的帮助。

  for (Element row : rows) {

                TableRow eins = new TableRow(this);
                Elements cells=row.select("td");
                for (Element cell : cells) {
                    TextView tv = new TextView(this);
                    if (cell.select("img").size() > 0) {
                    tv.setText("A ");
                    }
                    else {
                    tv.setText(" " + cell.text() + " ");
                    }
                    if (tv.length() < 9) {
                        tv.setGravity(Gravity.CENTER_HORIZONTAL);
                    }
                    eins.addView(tv);
                }           
                tbl.addView(eins);
            }

if 方向运算符

int orientation = getResources().getConfiguration().orientation;
if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
    // In landscape
} else {
    // In portrait
}

我自己搞定了。

int orientation = getResources().getConfiguration().orientation;
            if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
                tbl.setColumnCollapsed(0, true);
                // In landscape

            } else {
                tbl.setColumnCollapsed(0, true);
                tbl.setColumnCollapsed(4, true);
                tbl.setColumnCollapsed(5, true);
                tbl.setColumnCollapsed(6, true);
                tbl.setColumnCollapsed(7, true);
                // In portrait