增加Seekbar进度0.5 android

时间:2014-04-18 06:37:58

标签: android seekbar

我的搜索栏范围是2-15,我想在搜索栏上每次点击增加0.5。我浏览过,找不到办法。

在oncreate()

sbTaux.setProgress(0) //default value.

sbTaux.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener(){

    @Override
    public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {

        progress = progress / 1;
        progress = progress * 1;

        if (progress<=2){

            progress=2;
            sbTaux.setProgress(0);
        }

        else {}

        txTaux.setText(Util.decimalFormat(progress));

    }

    @Override
    public void onStartTrackingTouch(SeekBar seekBar) {

    }

    @Override
    public void onStopTrackingTouch(SeekBar seekBar) {

    }

});

2 个答案:

答案 0 :(得分:1)

制作范围4-30,然后将结果除以2应该做的诀窍

答案 1 :(得分:0)

 int myProgress;
 SeekBar seekBar = (SeekBar)layout.findViewById(R.id.seekbar);
 TextView seekBarValue = (TextView)layout.findViewById(R,id.TextView1);
 seekBar.setProgress(2);
 seekBar.incrementProgressBy(1/2);
 seekBar.setMax(15);
 seekbar.setOnSeekBarChangeListener(new OnSeekBarChangeListener(){
 @Override
 public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
    myProgress = progress;
    seekBarValue.setText(myProgress);
}

@Override
public void onStartTrackingTouch(SeekBar seekBar) {

}

@Override
public void onStopTrackingTouch(SeekBar seekBar) {

}