Привет всем, у меня возникла проблема с прогрессом на индикаторе выполнения. Я пытаюсь обновить прогресс на индикаторе выполнения, но по какой-то неизвестной причине он постоянно показывает значения 100 % или выше.
Ниже приведен соответствующий XML-код. и фрагменты кода Java:
public class FragmentResults extends Fragment {
ProgressBar overallScoreProgressBar;
int overall;
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.fragment_results, container, false);
// Initialize ProgressBars
overallScoreProgressBar = view.findViewById(R.id.overall_score_progress_bar);
// Generate random scores
generateRandomScores();
// Set progress bar colors based on scores
setProgressBarColor(overallScoreProgressBar, overall);
return view;
}
// Method to calculate color based on progress
private void setProgressBarColor(ProgressBar progressBar, int progress) {
int color = getColorFromProgress(progress);
progressBar.getProgressDrawable().setColorFilter(color, android.graphics.PorterDuff.Mode.SRC_IN);
}
// Method to determine the color based on the progress percentage
private int getColorFromProgress(int progress) {
if (progress 8) & 0xFF;
int bStart = colorStart & 0xFF;
int rEnd = (colorEnd >> 16) & 0xFF;
int gEnd = (colorEnd >> 8) & 0xFF;
int bEnd = colorEnd & 0xFF;
int r = (int) (rStart + (rEnd - rStart) * ratio);
int g = (int) (gStart + (gEnd - gStart) * ratio);
int b = (int) (bStart + (bEnd - bStart) * ratio);
return Color.rgb(r, g, b);
}
private void generateRandomScores() {
Random random = new Random();
// Generate random scores between 0 and 100
overall = random.nextInt(101);
// Other score generations
// Set scores to TextViews and progress bars
setScoresAndProgress();
}
private void setScoresAndProgress() {
// Set the scores to TextViews
overallScore.setText(String.valueOf(overall));
// Set the progress bars
overallScoreProgressBar.setProgress(overall);
}
}
Буду очень признателен за любые решения этой проблемы!
Привет всем, у меня возникла проблема с прогрессом на индикаторе выполнения. Я пытаюсь обновить прогресс на индикаторе выполнения, но по какой-то неизвестной причине он постоянно показывает значения 100 % или выше. [img]https://i.sstatic.net/2XFNeAM6.png[/img]
Ниже приведен соответствующий XML-код. и фрагменты кода Java: [code]
[/code] [code]public class FragmentResults extends Fragment { ProgressBar overallScoreProgressBar; int overall;
@Nullable @Override public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { // Inflate the layout for this fragment View view = inflater.inflate(R.layout.fragment_results, container, false);
// Set progress bar colors based on scores setProgressBarColor(overallScoreProgressBar, overall);
return view; }
// Method to calculate color based on progress private void setProgressBarColor(ProgressBar progressBar, int progress) { int color = getColorFromProgress(progress); progressBar.getProgressDrawable().setColorFilter(color, android.graphics.PorterDuff.Mode.SRC_IN); }
// Method to determine the color based on the progress percentage private int getColorFromProgress(int progress) { if (progress 8) & 0xFF; int bStart = colorStart & 0xFF;
int rEnd = (colorEnd >> 16) & 0xFF; int gEnd = (colorEnd >> 8) & 0xFF; int bEnd = colorEnd & 0xFF;
int r = (int) (rStart + (rEnd - rStart) * ratio); int g = (int) (gStart + (gEnd - gStart) * ratio); int b = (int) (bStart + (bEnd - bStart) * ratio);
return Color.rgb(r, g, b); }
private void generateRandomScores() { Random random = new Random();
// Generate random scores between 0 and 100 overall = random.nextInt(101);
// Other score generations
// Set scores to TextViews and progress bars setScoresAndProgress(); }
private void setScoresAndProgress() { // Set the scores to TextViews overallScore.setText(String.valueOf(overall));
// Set the progress bars overallScoreProgressBar.setProgress(overall); } } [/code] Буду очень признателен за любые решения этой проблемы!