简体   繁体   English

如何从Android中的TableLayout中完全隐藏一行?

[英]How to completely hide a row from TableLayout in Android?

The rows with the hours 18, 19, 20, 21 are hidden using the INVISIBLE option. 使用INVISIBLE选项隐藏小时为18,19,20,21的行。 But it still leaves the empty gap at the end. 但它仍然留下了空洞的空白。 Is there any way to remove that gap as well? 有没有办法消除这个差距?

private void hideEveningHours() {  // hiding evening rows
    TableRow tr = (TableRow)findViewById(R.id.row18);
    tr.setVisibility(View.INVISIBLE);
    tr = (TableRow)findViewById(R.id.row19);
    tr.setVisibility(View.INVISIBLE);
    tr = (TableRow)findViewById(R.id.row20);
    tr.setVisibility(View.INVISIBLE);
    tr = (TableRow)findViewById(R.id.row21);
    tr.setVisibility(View.INVISIBLE);
}

时间

Use 采用

View.GONE

instead of 代替

View.INVISIBLE

View.INVISIBLE only makes the View invisible. View.INVISIBLE仅使View不可见。 It is still added to the View hierarchy, and space is allocated for it. 它仍然添加到View层次结构中,并为其分配空间。 Whereas View.GONE removes the View from the ViewGroup as though it was never present in the first place. View.GONEViewGroup 删除 View ,就好像它从未出现在第一位。 What's more, you can get it back simply by setting its visibility to 更重要的是,只需将其可见性设置为,即可将其恢复

View.VISIBLE

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM