您好,我在 android 中有一个最大进度值为 100 的搜索栏。我希望搜索栏只能在 0-100 之间上升到 50。它不允许进度超过 50。我的逻辑是,我不想更改搜索栏进度的最大值。
请帮助我如何在 android 的 seekbar 中做到这一点。提前致谢。
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
sb1=(SeekBar) findViewById(R.id.seekBar1);
sb2=(SeekBar) findViewById(R.id.seekBar2);
sb3=(SeekBar) findViewById(R.id.seekBar3);
tv1=(TextView) findViewById(R.id.textView1);
tv2=(TextView) findViewById(R.id.textView2);
tv3=(TextView) findViewById(R.id.textView3);
tvremaining=(TextView) findViewById(R.id.textView4);
tvused=(TextView) findViewById(R.id.textView5);
sb1.setOnSeekBarChangeListener(this);
sb2.setOnSeekBarChangeListener(this);
sb3.setOnSeekBarChangeListener(this);
total=100;
used=0;
remaining=total-used;
tvremaining.setText(Integer.toString(remaining));
tvused.setText(Integer.toString(used));
}
@Override
public void onProgressChanged(SeekBar arg0, int arg1, boolean arg2)
{
switch (arg0.getId())
{
case R.id.seekBar1:
if(arg2)
{
tv1.setText(Integer.toString(arg1));
//arg0.setProgressDrawable(getResources().getDrawable(R.drawable.progress_normal));
}
break;
case R.id.seekBar2:
if(arg2)
{
tv2.setText(Integer.toString(arg1));
//arg0.setProgressDrawable(getResources().getDrawable(R.drawable.progress_normal));
}
break;
case R.id.seekBar3:
if(arg2)
{
tv3.setText(Integer.toString(arg1));
//arg0.setProgressDrawable(getResources().getDrawable(R.drawable.progress_normal));
}
break;
}
progress=arg1;
}
@Override
public void onStartTrackingTouch(SeekBar arg0)
{
//arg0.setMax(remaining);
// TODO Auto-generated method stub
}
@Override
public void onStopTrackingTouch(SeekBar arg0)
{
switch (arg0.getId())
{
case R.id.seekBar1:
//sb2.setProgressDrawable(getResources().getDrawable(R.drawable.progress_applied));
//sb3.setProgressDrawable(getResources().getDrawable(R.drawable.progress_applied));
sb2.setProgress(progress);
sb3.setProgress(progress);
break;
case R.id.seekBar2:
//sb1.setProgressDrawable(getResources().getDrawable(R.drawable.progress_applied));
//sb3.setProgressDrawable(getResources().getDrawable(R.drawable.progress_applied));
sb1.setProgress(progress);
sb3.setProgress(progress);
break;
case R.id.seekBar3:
//sb1.setProgressDrawable(getResources().getDrawable(R.drawable.progress_applied));
//sb2.setProgressDrawable(getResources().getDrawable(R.drawable.progress_applied));
sb1.setProgress(progress);
sb2.setProgress(progress);
break;
}
used= (Integer.parseInt(tv1.getText().toString()))+(Integer.parseInt(tv2.getText().toString()))+(Integer.parseInt(tv3.getText().toString()));
remaining = total-used;
tvremaining.setText(Integer.toString(remaining));
tvused.setText(Integer.toString(used));
// TODO Auto-generated method stub
}