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