0

When ScrollView first time appear, or there is a configuration change, the scroll bar will appear, then fading away.

If I do not want to show the ScrollView's scroll bar at all, I know I can

scrollView.setVerticalScrollBarEnabled(false);

during Activity's onCreate.

However, at the same time, I wish to display (then fading) the scroll bar, only when user is scrolling, so that he can have an idea what is the location of the scroll bar.

Is there any way I can have both

  1. Hide the scroll bar when the ScrollView first time appear, or there is configuration change.
  2. Show the scroll bar, when the user is scrolling.

1 Answer 1

1

Hide the scroll bar when the ScrollView first time appear, or there is configuration change.

Use:

scrollView.setVerticalScrollBarEnabled(false);

in the onCreate method.

Show the scroll bar, when the user is scrolling.

Use:

@Override
protected void onResume() { 
    super.onResume();
    scrollView.post(new Runnable() {

        @Override
        public void run() {              
           scrollView.setVerticalScrollBarEnabled(true);                
        }
    });
}

for the onResume() method.

When ScrollView first time appear, or there is a configuration change, the scroll bar will appear, then fading away.

I would keep it, it was designed that way so the user always has a clear visual indicator that the content can be scrolled(and the direction in which it can be scrolled).

Sign up to request clarification or add additional context in comments.

3 Comments

Sorry. It suppose to work by looking at the code. However, I did a testing today. It turn out it is not 100% working. Look like posting runnable during resume, will still show up the scroll bar to user during first time appearing. But, that do prevent scroll bar from showing during configuration change.
@CheokYanCheng So it doesn't work for the first time the app starts but it works for any configuration changes?
Seems like you'd want it in onCreateView instead, since onCreateView will not get called after first time.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.