Android学习-ProgressBar、SeekBar

seekbar手动拖动与progressbar进度绑定

  • 布局代码


     
    
     
    
     
    

`

  • 活动代码
public class Test extends AppCompatActivity {
     
    private ProgressBar progressBar;
    private SeekBar seekBar;
    private TextView tvprogress;
    protected void onCreate(Bundle savedInstanceState) {
     
        super.onCreate(savedInstanceState);
        setContentView(R.layout.test);
        initView();

    }
    public void initView(){
     
        progressBar = findViewById(R.id.progress2);
        seekBar = findViewById(R.id.seekbar);
        tvprogress = findViewById(R.id.tv_Progress);

        seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
     
            @Override
            public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
     
                //滑杆值发生改变,此方法被触发。1.本身,2.进度栏
                progressBar.setProgress(progress);//滑杆走多少,进度条走多少
                tvprogress.setText("当前进度为" + progress + "%");
            }

            @Override
            public void onStartTrackingTouch(SeekBar seekBar) {
     
                //有touch行为时会触发
            }

            @Override
            public void onStopTrackingTouch(SeekBar seekBar) {
     
                //拖动停止时会触发
                if(progressBar.getProgress() >= progressBar.getMax()){
     
                    progressBar.setVisibility(View.INVISIBLE);
                }else{
     
                    progressBar.setVisibility(View.VISIBLE);
                }
            }
        });
    }

}

很简单,不知道有用没。。。

你可能感兴趣的:(Android,安卓,android,studio,android)