private static int INCREMENT_BY = 10;
private static int MAX = 1000;
private static int MIN = 0;
SeekBar seekbar_min, seekbar_max;
private int max = 0, min = 0;
seekbar_min.setProgress(MIN);
seekbar_min.incrementProgressBy(INCREMENT_BY);
seekbar_min.setMax(MAX);
seekbar_min.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
progress = progress / INCREMENT_BY;
progress = progress * INCREMENT_BY;
if (progress < 100) {
min = progress * 10;
} else if (progress < 300) {
min = progress * 50;
} else if (progress < 900) {
min = progress * 100;
} else {
min = progress * MAX;
}
tv_price_min.setText(String.valueOf(min));
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
if (seekBar.getProgress() != MIN || seekBar.getProgress() != MAX){
if (seekBar.getProgress() < 100) {
max = seekBar.getProgress() + 10;
} else if (seekBar.getProgress() < 300) {
max = seekBar.getProgress() + 50;
} else if (seekBar.getProgress() < 900) {
max = seekBar.getProgress() + 100;
} else {
max = seekBar.getProgress() + MAX;
}
seekbar_max.setProgress(max);
}
}
});
seekbar_max.incrementProgressBy(INCREMENT_BY);
seekbar_max.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
progress = progress / INCREMENT_BY;
progress = progress * INCREMENT_BY;
if (progress < 100) {
max = progress * 10;
} else if (progress < 300) {
max = progress * 50;
} else if (progress < 900) {
max = progress * 100;
} else {
max = progress * MAX;
}
tv_price_max.setText(String.valueOf(max));
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
});
Seek条的最高价格必须具有最小值,即最小搜索条当前值。我可以成功地做到这一点,但问题是,最大搜索栏允许将最小值更改为0,这是我不想要的。
答案 0 :(得分:5)
Seekbar
没有setMin
功能。默认最小值为零。如果您想为Seekbar
设置最小值,那么您可以有两个选项:
if (seekbar.getProgress() < MIN_VALUE) { seekbar.setProgress(MIN_VALUE); }
答案 1 :(得分:1)
试试这个,我能够在我的一个项目上做到这一点。在这种情况下,最大值为23,最小值为8.
const obj = {
name: 'kung',
foo: function(){
console.log('foo');
}
};
function invokeMethod(obj, method) {
if((method in obj) && typeof obj[method] ==="function"){
return obj[method]();
}
}
invokeMethod(obj, 'foo');
答案 2 :(得分:0)
实际上您无法定义最小值。 但是我总是使用Trick:
在&#34; onProgressChanged&#34; Metod,放置此代码
int min = 1; //The Min Value You Want To
int progressValue;
if( i < min ) { // i : Progress Value
progressValue = min;
seekBar.setProgress(min);
}else progressValue = i;
答案 3 :(得分:0)
我找到了一种最简单的方法(仅API 25以上)。有一种setMin(int number)
方法。
seekbar.setMax(6);
seekbar.setMin(1);
问题在于,您必须将build gradle中的最低API设置为25或更高