问题
Is there a function (or an XML tag) which allows to change the width of thumb in the seekBar dynamically , when the maxValue is changed . For example if the maxValue == 2 the Thumb takes the half of the whole Seekbar , then if maxValue is 3 , it takes the 1/3-th of the width , and so on .
回答1:
The SeekBar thumb can only be set in XML, not dynamically. What you are looking for is akin to a scrollbar. Views which are scrollable, like ListView, have these built in, so you don't need to do anything.
回答2:
You need to programatically implement the logic..by using thumsize and progress values and implementing OnSeekBarChangeListener
You can ask if you have any further queries :)
回答3:
If you're targeting only android devices running v16+, you might be able to do this using getThumb().setBounds()
, but doing so may have consequences if you do it whilst the user is touching the view.
You will also want to update the offset using setThumbOffset()
passing in 1/2 the width of the new bounds.
You can also just replace the thumb with a new drawable, which will update the offset for you (if you have a symmetrical drawable), but adjust its bounds is probably going to be more efficient.
来源:https://stackoverflow.com/questions/21401884/android-resizing-seekbar-thumb-width-from-maximum-value