从最大值Android的大小调整搜索栏拇指宽 [英] Android resizing SeekBar thumb width from maximum value

查看:326
本文介绍了从最大值Android的大小调整搜索栏拇指宽的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有一个功能(或XML标签),其允许动态改变拇指的宽度在搜索栏,当maxValue分别被改变。为如果maxValue分别== 2的拇指取整个搜索栏的半例子中,那么如果maxValue分别是3,它需要的宽度的1/3个,等等。

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 .

推荐答案

如果你的目标运行V16 +只有Android设备,你也许可以做到这一点使用 getThumb()的setBounds(),但这样做,如果你做到这一点,而用户触摸视图可能产生的后果。

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.

您还需要更新使用 setThumbOffset()传球抵消了1/2的新边界的宽度。

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.

这篇关于从最大值Android的大小调整搜索栏拇指宽的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆