0

I've tried to find out how to set scrollview thumb with a fixed height. Eventually, I did it by overriding ScrollView method, but I think it's not a good solution. Is there a more simple way of solving my issue.

The main problem was the thumb stretches depends on contents inside scrollview I've set It's fixed size by overriding computeVerticalScrollExtent and recalculate offset in computeVerticalScrollOffset. Something like that

public class MyScrollView extends ScrollView {

    static final int CONST_THUMB = 100; // thumb height
    float divider = 1;

    public MyScrollView(Context context) {
        super(context);
    }

    @Override
    public int computeVerticalScrollExtent() {

    int length = computeVerticalScrollRange() - 
                 super.computeVerticalScrollExtent();
    if(length > 0)
           divider = (float )(computeVerticalScrollRange() - 
                              CONST_THUMB)/(float )length;
    else
         return super.computeVerticalScrollExtent();

    return CONST_THUMB;
    }

    @Override
    public int computeVerticalScrollOffset() {
        return (int )((float )super.computeVerticalScrollOffset() * divider);
    }
}

It's set a fixed thumb height, and works for me, Is Android has a more effective solution? I need to have a thumb like a vertical SeekBar

lexxvis
  • 9
  • 2
  • Possible duplicate of [How to set scrollbar thumb programmatically in Android?](https://stackoverflow.com/questions/9713909/how-to-set-scrollbar-thumb-programmatically-in-android) – MSpeed Apr 23 '19 at 14:57
  • Thanks, interesting way to change appearance of thumb but unfortunately height stretches – lexxvis Apr 23 '19 at 18:31

0 Answers0