I have a header view in a ListView
I want to hide when not in use. I've included code that sets its visibility to View.GONE
or View.VISIBLE
depending on another control.
Unfortunately, the view I am trying to show and hide is laying out as though I were setting its visibility to View.INVISIBLE
—that is, the ListView
is allowing space for it even when it's hidden. How can I prevent this?
I have tried calling requestLayout()
and it hasn't had any effect.
I am going to try one of the suggested solutions here:
namely, wrapping my header in a FrameLayout
and letting the FrameLayout
handle the layout change, not the ListView
.
EDIT: I have found that basically the same bug occurs when I added a ViewPager
subclass in which I had overridden onMeasure(int widthMeasureSpec, int heightMeasureSpec)
as a header view: it was designed to lay itself out again when children were added, but the ListView
displayed it wrongly. As a child of a LinearLayout
, however, this worked fine.