Android resizing SeekBar thumb width from maximum value

≯℡__Kan透↙ 提交于 2019-12-25 02:16:36

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!