Невозможно программно установить прогресс в индикаторе выполненияAndroid

Форум для тех, кто программирует под Android
Ответить
Anonymous
 Невозможно программно установить прогресс в индикаторе выполнения

Сообщение Anonymous »

Привет всем, у меня возникла проблема с прогрессом на индикаторе выполнения. Я пытаюсь обновить прогресс на индикаторе выполнения, но по какой-то неизвестной причине он постоянно показывает значения 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);
}
}

Я был бы очень признателен за любые решения этой проблемы!
РЕДАКТИРОВАТЬ: - По просьбе @Kaung Khat Kyaw делюсь всем кодом
public class FragmentResults extends Fragment {

TextView overallScore, potentialScore, masculinityScore, jawlineScore,skinScore, cheekboneScore, eyesScore, hairScore;
ProgressBar overallScoreProgressBar, potentialScoreProgressBar, masculinityScoreProgressBar,
skinScoreProgressBar, jawlineScoreProgressBar, cheekboneScoreProgressBar, eyesScoreProgressBar, hairScoreProgressBar;

SeekBar seekBar;

int overall,potential,skin,masculinity,jawline,cheekbone,eyes,hair;

@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 TextViews
overallScore = view.findViewById(R.id.overall_score);
potentialScore = view.findViewById(R.id.potential_score);
masculinityScore = view.findViewById(R.id.masculinity_score);
jawlineScore = view.findViewById(R.id.jawline_score);
cheekboneScore = view.findViewById(R.id.cheekbone_score);
eyesScore = view.findViewById(R.id.eyes_score);
hairScore = view.findViewById(R.id.hair_score);
skinScore = view.findViewById(R.id.skin_score);

// Initialize ProgressBars
overallScoreProgressBar = view.findViewById(R.id.overall_score_progress_bar);
potentialScoreProgressBar = view.findViewById(R.id.potential_score_progress_bar);
masculinityScoreProgressBar = view.findViewById(R.id.masculinity_score_progress_bar);
jawlineScoreProgressBar = view.findViewById(R.id.jawline_score_progress_bar);
cheekboneScoreProgressBar = view.findViewById(R.id.cheekbone_score_progress_bar);
eyesScoreProgressBar = view.findViewById(R.id.eyes_score_progress_bar);
hairScoreProgressBar = view.findViewById(R.id.hair_score_progress_bar);
skinScoreProgressBar= view.findViewById(R.id.skin_score_progress_bar);

// Generate random scores
generateRandomScores();

// Set progress bar colors based on scores
setProgressBarColor(overallScoreProgressBar, overall);
setProgressBarColor(potentialScoreProgressBar, potential);
setProgressBarColor(masculinityScoreProgressBar, masculinity);
setProgressBarColor(jawlineScoreProgressBar, jawline);
setProgressBarColor(cheekboneScoreProgressBar, cheekbone);
setProgressBarColor(eyesScoreProgressBar, eyes);
setProgressBarColor(hairScoreProgressBar, hair);
setProgressBarColor(skinScoreProgressBar,skin);

seekBar = view.findViewById(R.id.hotnessscoreProgressBar);
// Create a Bitmap with the fire emoji
Paint paint = new Paint();
paint.setTextSize(60); // Adjust the size for the emoji
paint.setColor(Color.BLACK);
paint.setTextAlign(Paint.Align.CENTER);
paint.setAntiAlias(true); // Ensures smooth edges

// Create a Bitmap with transparent background (ARGB_8888 supports transparency)
Bitmap bitmap = Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);

// Clear the canvas with transparent color
canvas.drawColor(Color.TRANSPARENT);

// Draw the emoji onto the canvas, centered
canvas.drawText("🔥", 50, 75, paint);

// Create a BitmapDrawable from the Bitmap
BitmapDrawable thumbDrawable = new BitmapDrawable(getResources(), bitmap);

// Set the bounds for the thumb drawable (adjust as needed)
thumbDrawable.setBounds(0, 0, 100, 100);

// Apply the thumb drawable to the SeekBar
seekBar.setThumb(thumbDrawable);

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);
potential = random.nextInt(101);
masculinity = random.nextInt(101);
jawline = random.nextInt(101);
cheekbone = random.nextInt(101);
skin = random.nextInt(101);
eyes = random.nextInt(101);
hair = random.nextInt(101);

// Set scores to TextViews and progress bars
setScoresAndProgress();
}

private void setScoresAndProgress() {
// Set the scores to TextViews
overallScore.setText(String.valueOf(overall));
potentialScore.setText(String.valueOf(potential));
masculinityScore.setText(String.valueOf(masculinity));
jawlineScore.setText(String.valueOf(jawline));
cheekboneScore.setText(String.valueOf(cheekbone));
eyesScore.setText(String.valueOf(eyes));
hairScore.setText(String.valueOf(hair));
skinScore.setText(String.valueOf(skin));

// Set the progress bars
overallScoreProgressBar.setProgress(overall);
potentialScoreProgressBar.setProgress(potential);
masculinityScoreProgressBar.setProgress(masculinity);
jawlineScoreProgressBar.setProgress(jawline);
cheekboneScoreProgressBar.setProgress(cheekbone);
eyesScoreProgressBar.setProgress(eyes);
hairScoreProgressBar.setProgress(hair);
skinScoreProgressBar.setProgress(skin);
}

}


Подробнее здесь: https://stackoverflow.com/questions/790 ... amatically
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «Android»