Changing step values in seekbar?

前端 未结 8 1943
耶瑟儿~
耶瑟儿~ 2020-12-12 16:32

I have a seekbar, while moving it I want to change values from 0 to 200. I have a TextView, where I display those values while moving the seekbar. But I don\'t want to have

相关标签:
8条回答
  • 2020-12-12 17:07

    Try below code

    SeekBar seekBar = (SeekBar)layout.findViewById(R.id.seekbar);
    seekBar.setProgress(0);
    seekBar.incrementProgressBy(10);
    seekBar.setMax(200);
    TextView seekBarValue = (TextView)layout.findViewById(R.id.seekbarvalue);
    seekBarValue.setText(tvRadius.getText().toString().trim());
    
    seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener(){
    
        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            progress = progress / 10;
            progress = progress * 10;
            seekBarValue.setText(String.valueOf(progress));
        }
    
        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {
    
        }
    
        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {
    
        }
    });
    

    setProgress(int) is used to set starting value of the seek bar

    setMax(int) is used to set maximum value of seek bar

    If you want to set boundaries of the seekbar then you can check the progressbar value in the onProgressChanged method. If the progress is less than or greater than the boundary then you can set the progress to the boundary you defined.

    0 讨论(0)
  • 2020-12-12 17:07

    One possible solution would be to set seekBar.setMax(20) (or android:max="20" in XML), and whenever you use or display the value, multiply it by 10.

    The SeekBar would then appear to move at least 20 at a time.

    0 讨论(0)
提交回复
热议问题