Prevent SeekBar from moving past a dynamic point

谁都会走 提交于 2019-12-11 12:53:11

问题


I need two SeekBars for setting a minimum and maximum, and the thumb on each SeekBar cannot move past the other. Is there a way to disallow moving the SeekBar past a specific point?


回答1:


Found the solution myself: in SeekBar.OnSeekBarChangeListener.onProgressChanged() method, just set the progress to a correct value, which in this case is the same as the other SeekBar

@Override
public void onProgressChanged(SeekBar seekBar, int progress,
            boolean fromUser) {
    if (!isLegalMove(seekBar)) {
        seekBar.setProgress(mOtherSeekBar.getProgress());
    } 
}

private boolean isLegalMove(SeekBar thisSeekBar) {
    if (mOtherSeekBar == null) {
        return true;
    }
    return mIsMax && mOtherSeekBar.getProgress() <= thisSeekBar.getProgress() ||
        !mIsMax && mOtherSeekBar.getProgress() >= thisSeekBar.getProgress();
}


来源:https://stackoverflow.com/questions/4731727/prevent-seekbar-from-moving-past-a-dynamic-point

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