如何在seekbar上显示一些值作为默认值?

我有一个seekbar例如:从0到10.我怎么能如果我想设置seekbar为5作为默认位置。 所以在这个例子中,seekbar应该从中间开始。

Solutions Collecting From Web of "如何在seekbar上显示一些值作为默认值?"

使用这个

android:progress="5" 

像“进度”一样,它从ProgressBarinheritance了它的一些属性。 你可以在http://developer.android.com/reference/android/widget/SeekBar.htmlfind所有的属性

让Seekbar的值为5

在xml布局中使用最大值为10

  android:max="10" 

在java for seekbar进展5

  seekbar = (SeekBar) findViewById(R.id.seekBar1); seekbar.setProgress(5); 

而已 :)

我希望这个代码能够帮助你。
尝试这个…

 float discrete=0; float start=0; float end=100; float start_pos=0; int start_position=0; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); start=-10; //you need to give starting value of SeekBar end=10; //you need to give end value of SeekBar start_pos=5; //you need to give starting position value of SeekBar start_position=(int) (((start_pos-start)/(end-start))*100); discrete=start_pos; SeekBar seek=(SeekBar) findViewById(R.id.seekBar1); seek.setProgress(start_position); seek.setOnSeekBarChangeListener(new OnSeekBarChangeListener() { @Override public void onStopTrackingTouch(SeekBar seekBar) { // TODO Auto-generated method stub Toast.makeText(getBaseContext(), "discrete = "+String.valueOf(discrete), Toast.LENGTH_SHORT).show(); } @Override public void onStartTrackingTouch(SeekBar seekBar) { // TODO Auto-generated method stub } @Override public void onProgressChanged(SeekBar seekBar, int progress,boolean fromUser) { // TODO Auto-generated method stub // To convert it as discrete value float temp=progress; float dis=end-start; discrete=(start+((temp/100)*dis)); } }); } 
 final Timer timer = new Timer(); seekBar_efficiency.setMax(40); seekBar_efficiency.setProgress(35); timer.schedule(new TimerTask() { @Override public void run() { seekBar_efficiency.setProgress(20); timer.cancel(); } }, 200, 50);