We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
由于想要用一套layout来复用,想要在代码离根据不同的数据设置不同的tickcount和max等参数,然后发现setProgress无效,出问题的代码是这样:
preference.seekBar.tickCount = 4 preference.seekBar.min = 0.toFloat() preference.seekBar.max = 3.toFloat() preference.seekBar.setProgress(1.0f)
经过检查发现是setProgress时会在一个数组mProgressArr里找最接近参数传进来的值,这个mProgressArr里的值本应该是seekbar中每个刻度(tick)的对应的值,换言之在本例子应该为[0.0, 1.0, 2.0, 3.0]
setProgress
mProgressArr
seekbar
但是mProgressArr此时里面的值为[0.0, 33.333, 66.666, 100]
进一步排查发现在setTickCount的时候才会重新计算这个mProgressArr里的值,关键在于下面这段代码
setTickCount
mProgressArr = new float[mTicksCount]; for (int i = 0; i < mProgressArr.length; i++) { mProgressArr[i] = mMin + i * (mMax - mMin) / ((mTicksCount - 1) > 0 ? (mTicksCount - 1) : 1); }
可以看到时通过min和max来计算出每个 tick 对应的值的,所以用例代码无法工作的理由在于应该先调用setMin和setMax再调用setTickCount
min
max
setMin
setMax
建议setMin和setMax方法也要重新计算这个mProgressArr
The text was updated successfully, but these errors were encountered:
No branches or pull requests
由于想要用一套layout来复用,想要在代码离根据不同的数据设置不同的tickcount和max等参数,然后发现setProgress无效,出问题的代码是这样:
经过检查发现是
setProgress
时会在一个数组mProgressArr
里找最接近参数传进来的值,这个mProgressArr
里的值本应该是seekbar
中每个刻度(tick)的对应的值,换言之在本例子应该为[0.0, 1.0, 2.0, 3.0]但是
mProgressArr
此时里面的值为[0.0, 33.333, 66.666, 100]进一步排查发现在
setTickCount
的时候才会重新计算这个mProgressArr
里的值,关键在于下面这段代码可以看到时通过
min
和max
来计算出每个 tick 对应的值的,所以用例代码无法工作的理由在于应该先调用setMin
和setMax
再调用setTickCount
建议
setMin
和setMax
方法也要重新计算这个mProgressArr
The text was updated successfully, but these errors were encountered: