Tad Lithuania Tad Lithuania - 3 months ago 17
Java Question

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. 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);
}


The hours

Answer

Use

View.GONE

instead of

View.INVISIBLE

View.INVISIBLE only makes the View invisible. It is still added to the View hierarchy, and space is allocated for it. Whereas View.GONE removes the View from the ViewGroup as though it was never present in the first place. What's more, you can get it back simply by setting its visibility to

View.VISIBLE
Comments