【问题标题】:java / android: table layout - visibility of specific columnjava / android:表格布局 - 特定列的可见性
【发布时间】:2020-08-29 12:12:28
【问题描述】:

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

感谢您的帮助。

  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
}

【问题讨论】:

    标签: java android tablelayout


    【解决方案1】:

    自己搞定的。

    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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-04-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多