two Bars which shows the progress of a game. If the user get points or time is up etc the progressBars should be updated:
private TextView tv;
private Progre
Nothing here worked for me, so I've came with a bit different solution. I noticed that everything is working well until I try to change maximal value (calling setMax with different value).
My code:
class FixedSeekBar : SeekBar {
constructor(context: Context) : super(context)
constructor(context: Context, attrs: AttributeSet) : super(context, attrs)
constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int) : super(context, attrs, defStyleAttr)
companion object {
private const val PROGRESS_MAX = 1000000.toDouble()
}
private var mLastMaxValue: Int = 100
override fun setMax(max: Int) {
mLastMaxValue = max
super.setMax(PROGRESS_MAX.toInt())
}
fun setProgressFixed(progress: Int) {
setProgress((PROGRESS_MAX / mLastMaxValue * progress).toInt())
}
fun getProgressFixed(): Int {
return (getProgress() / PROGRESS_MAX * mLastMaxValue).toInt()
}
}
This works perfectly for me. I can call setMax as usually and I just need to replace getProgress and setProgress with getProgressFixed and setProgressFixed.
Do not override setProgress and getProgress. They are called internally.
My solution doesn't count with setMin. If you need it, change the code accordingly.