SeekBar 设置任意区间负数

首先上一张图片

SeekBar 设置任意区间负数_第1张图片

 

布局文件

 




    

    

    

        

        
    

 

drawable_seekbar.xml


    
        
            
        
    
    
        
            
                
            
        
    
    
        
            
                
            
        
    

 

seekbar_thumb.xml



    
    
    
    

 

 


        String currentValue = "-16";
        String lowValue = "-18";
        String highValue = "-3";
        final String tempValue = String.valueOf(0 - Integer.parseInt(lowValue));
        seekBarView = (TextView) findViewById(R.id.text);
        tv_low = (TextView) findViewById(R.id.text1);
        tv_low.setText(lowValue);
        tv_hige = (TextView) findViewById(R.id.text2);
        tv_hige.setText(highValue);
        SeekBar mSeekBar = (SeekBar) findViewById(R.id.seekbar);
        mSeekBar.setMax(Integer.parseInt(highValue) - Integer.parseInt(lowValue));
        mSeekBar.setProgress(Integer.parseInt(currentValue) + Integer.parseInt(tempValue));
        seekBarView.setText("当前温度:" + String.valueOf(currentValue) + "°C");
        mSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
            @Override
            public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
                seekBarView.setText("当前温度:" + String.valueOf(progress - Integer.parseInt(tempValue)));
            }

            @Override
            public void onStartTrackingTouch(SeekBar seekBar) {

            }

            @Override
            public void onStopTrackingTouch(SeekBar seekBar) {

            }
        });


 

你可能感兴趣的:(Android基础)