How to minimize size of scrollview after hiding UI elements inside in Android?

I have a ScrollView and i’m hiding some UI Elements inside by calling

suffixSpinner.setVisibility(View.INVISIBLE);
serviceLineTextView.setVisibility(View.INVISIBLE);
subscriberIdTextView.setVisibility(View.INVISIBLE);
suffixTextView.setVisibility(View.INVISIBLE);

This creates white space in the ScrollView where the UI elements once were.
How do I remove that white space and minimize the ScrollView to fit again?

3
Leave a Reply

avatar
3 Comment threads
0 Thread replies
0 Followers
 
Most reacted comment
Hottest comment thread
1 Comment authors
Jason Recent comment authors
  Subscribe  
newest oldest most voted
Notify of
Jason
Guest

We have to way to hide view in android

First View.INVISIBLE This view is invisible, but it still takes up space for layout purposes.

Second View.GONE This view is invisible, and it doesn’t take any space for layout purposes.

View.INVISIBLE

enter image description here

View.GONE

enter image description here

Replace Code With This:

suffixSpinner.setVisibility(View.GONE);
serviceLineTextView.setVisibility(View.GONE);
subscriberIdTextView.setVisibility(View.GONE);
suffixTextView.setVisibility(View.GONE);

Jason
Guest

use View.GONE instead. View.INVISIBLE will still take up the required space in the view.

Jason
Guest

Take a look at doc
View.Gone
View.INVISIBLE

View.GONE This view is invisible, and it doesn’t take any space for layout purposes.

View.INVISIBLE This view is invisible, but it still takes up space for layout purposes.