1.进度条范围0-39
prams.leftMargin:TextView的左右移动大小
String lowValue = "0";
String highValue = "39";
String currentValue = "0";
final String tempValue = String.valueOf(0 - Integer.parseInt(lowValue));
sb_quota.setMax(Integer.parseInt(highValue) - Integer.parseInt(lowValue));
sb_quota.setProgress(Integer.parseInt(currentValue) + Integer.parseInt(tempValue));
sb_quota.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
tv_quota.setText(""+progress);
Log.d(TAG,"progress = "+progress);
// quota = progress;
int spec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
tv_quota.measure(spec, spec);
int quotaWidth = tv_quota.getMeasuredWidth();
int spec2 = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
tv_quota.measure(spec2, spec2);
int sbWidth = sb_quota.getMeasuredWidth();
LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) tv_quota.getLayoutParams();
// params.leftMargin = (int) (((double) progress / sb_quota.getMax()) * sbWidth - (double) quotaWidth * progress / sb_quota.getMax());
params.leftMargin = (int) (((double) progress / sb_quota.getMax()) * sbWidth - (double) quotaWidth * progress / sb_quota.getMax() + 54);
if (progress >= 10 && progress <= 38){
params.leftMargin = params.leftMargin - 20;
}else if (progress >= 39){
params.leftMargin = (int) (((double) progress / sb_quota.getMax()) * sbWidth - (double) quotaWidth * progress / sb_quota.getMax());
}
tv_quota.setLayoutParams(params);
Log.d(TAG,"setLayoutParams = "+params.leftMargin);
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
tv_quota.setVisibility(View.VISIBLE);
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
tv_quota.setVisibility(View.INVISIBLE);
}
});
2.进度条范围-14 -- 14;(从打印来看数值其实是0-28,想要负值mProgress = progress -14;)
prams.topMargin:TextView的上下移动大小
String lowValue = "-14";
String highValue = "14";
String currentValue = "0";
final String tempValue = String.valueOf(0 - Integer.parseInt(lowValue));
sb_quota.setMax(Integer.parseInt(highValue) - Integer.parseInt(lowValue));
sb_quota.setProgress(Integer.parseInt(currentValue) + Integer.parseInt(tempValue));
sb_quota.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
int mProgress;
mProgress = progress -14;
tv_quota.setText(""+mProgress);
Log.d(TAG,"progress = "+mProgress);
// quota = progress;
int spec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
tv_quota.measure(spec, spec);
int quotaWidth = tv_quota.getMeasuredWidth();
int spec2 = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
tv_quota.measure(spec2, spec2);
int sbWidth = sb_quota.getMeasuredWidth();
LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) tv_quota.getLayoutParams();
// params.leftMargin = (int) (((double) progress / sb_quota.getMax()) * sbWidth - (double) quotaWidth * progress / sb_quota.getMax());
params.topMargin = (int) (((double) progress / sb_quota.getMax()) * sbWidth - (double) quotaWidth * progress / sb_quota.getMax() + 54);
if (progress >= 10 && progress <= 38){
params.topMargin = params.topMargin - 20;
}else if (progress >= 39){
params.topMargin = (int) (((double) progress / sb_quota.getMax()) * sbWidth - (double) quotaWidth * progress / sb_quota.getMax());
}
tv_quota.setLayoutParams(params);
Log.d(TAG,"setLayoutParams = "+params.leftMargin);
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
tv_quota.setVisibility(View.VISIBLE);
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
tv_quota.setVisibility(View.INVISIBLE);
}
});