1

In iOS I can easily change the inset of the scrollbar in a UIScrollView by setting the scrollIndicatorInsets. Basically what happens is the UIScrollView size and content area stays the same, yet the scrollbar can be smaller, which is very nice when using some (semi-transparent) overlays over the top or bottom of the scrollview, since the scrollbar won't be hidden behind the overlays.

If it possible to achieve the same result in Android? Could I have a full-size scrollview, yet have a smaller sized scrollbar (e.g. scrollview begins at pixel 0 and ends at pixel 100, scrollbar begins at pixel 10 and ends at pixel 90? If possible, how do I achieve this?

1 Answer 1

2

From what I have seen, there is no API provided by Google to do this. You may have to inherit from ScrollView and override some method to achieve this effect. Something like this, perhaps:

@Override
protected void onDrawVerticalScrollBar(Canvas canvas,
                                       Drawable scrollBar,
                                       int l, int t, int r, int b) {
    scrollBar.setBounds(l, t + mVerticalScrollInset, r, b);
    scrollBar.draw(canvas);
}

Here mVerticalScrollInset is a private variable in your class. I have a similar problem. I'm setting this variable in code, to achieve different vertical scroll insets dynamically as required by my application.

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

1 Comment

how do I do this in Objective-C?

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.