I\'ve got a view that is effectively is a button. Here is its XML layout (add_new.xml)
A generic and easy solution is to avoid all thuse heck of code:
You need to add a Container Layout or a Parent Layout over your set of views that you want to hide. It can be anything like CardView or FrameLayout or etc.
Just it has to be a parent for that view that you want to hide. And you wont get all those white spaces. Coz it will consider the entire container to hide instead of considering individual views to HIDE thus, avoiding the white spaces.