好的,所以我已经能够自定义一些 SeekBar 以用作条形图类型的图像,但是因为我需要能够在绿色或红色图像(取决于某些值)之间切换,您可以在下面看到。问题是,无论我在 setLevel 中为 Drawable 使用什么值,它都不能正确填充(您可以查看下图作为示例,因为根据这两个值,绿色条应该更靠近右侧)
下面是设置整个 MTD 佣金栏部分的代码,我不知道您需要查看多少代码,所以我决定发布所有这一部分。
void setupMTDBarSection() {
//Get Current Date and Number of Days in Current Month
Calendar cal = Calendar.getInstance();
int numberOfDays = cal.getActualMaximum(Calendar.DAY_OF_MONTH);
SimpleDateFormat today = new SimpleDateFormat("dd");
String currentDate = today.format(new Date());
//Get MTD Goal value from Preferences
String goalString = preferences.getString("keyMonthlyGoal", "0");
float mtdGoalFloat = Float.valueOf(goalString);
Integer mtdGoal = (int)mtdGoalFloat;
MTDGoalValue.setText(NumberFormat.getCurrencyInstance().format(mtdGoalFloat));
//Get Current MTD Value
String mtdString = preferences.getString("keyMTDValue", "0");
float mtdValueFloat = Float.valueOf(mtdString);
Integer mtdValue = (int)mtdValueFloat;
MTDCurrentProgress.setText(NumberFormat.getCurrencyInstance().format(mtdValueFloat));
//Do some math to determine if the Rep is below/above the daily goal
Integer dailyGoal = mtdGoal/numberOfDays;
Integer currentDayGoal = dailyGoal * Integer.valueOf(currentDate);
if (mtdValue >= currentDayGoal) {
MTDGreenTrack.setLevel(mtdValue);
MTDProgressBar.setProgressDrawable(MTDGreenTrack);
MTDProgressBar.setMax(mtdGoal);
MTDProgressBar.setProgress(mtdValue);
}
else {
MTDRedTrack.setLevel(mtdValue);
MTDProgressBar.setProgressDrawable(MTDRedTrack);
MTDProgressBar.setMax(mtdGoal);
MTDProgressBar.setProgress(mtdValue);
}
//Add Percentage to MTD Text
NumberFormat percentFormat = NumberFormat.getPercentInstance();
float percent = mtdValueFloat/mtdGoalFloat;
String percentage = percentFormat.format(percent);
MTDPercentText.setText("(" + percentage + ")");
//Setup MTD Indicator
MTDIndicator.setMax(numberOfDays);
MTDIndicator.setProgress(Integer.valueOf(currentDate));
MTDIndicator.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
return true;
}
});
}