Android seekBar的使用

以下代码为应用项目中SeekBar的全部内容和代码展示:

xml  文件中

  

java 代码:

  1.监听器

       seekBar.setOnSeekBarChangeListener(seekBarChangeListener);

 private double from;//返点拉杆最小值
    private double gap;//拉杆的间隔
    private double to;//返点拉杆的最大值 

 SeekBar.OnSeekBarChangeListener seekBarChangeListener = new SeekBar.OnSeekBarChangeListener() {
        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            double p = 0.0;
            if (progress == 0) {
                p = to;
            } else if (progress == seekBar.getMax()) {
                p = from;
            } else {
                progress = seekBar.getMax() - progress;
                p = progress * gap;
            }
            infoPresenter.changePrize(p);
            tvstatus.setText(getString(R.string.strPercentFormat, UnitUtil.get1Decimal(p * 100)));

        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {

        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {

        }
    };
    seekBar.setMax((int) (this.to / this.gap));

   seekBar.setProgress((int) (this.to / this.gap));//初始化拉杆

你可能感兴趣的:(安卓)