开发者

Prevent SeekBar from moving past a dynamic point

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 pas开发者_如何学编程t a specific point?


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();
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜