-4
中動態創建評級欄的評級欄中更改星星的顏色我像這樣動態創建我的佈局。我想將此評分欄中的星星顏色從默認藍色更改爲黃色。在android
View insertPhoto(int id, int i){
layout = new LinearLayout(getApplicationContext());
layout.setLayoutParams(new LayoutParams(180, 250));
layout.setGravity(Gravity.CENTER);
layout.setOrientation(1);
layout.setId(i);
FrameLayout fl=new FrameLayout(getApplicationContext());
fl.setLayoutParams(new LayoutParams(116, 116));
imageView = new ImageView(getApplicationContext());
imageView.setLayoutParams(new LayoutParams(116,116));
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
imageView.setImageResource(id);
imageView.setId(i);
imgoff = new ImageView(getApplicationContext());
imgoff.setLayoutParams(new LayoutParams(50,116));
imgoff.setScaleType(ImageView.ScaleType.FIT_END);
imgoff.setImageResource(getResources().getIdentifier("offer","drawable", getPackageName()));
// imgoff.setOnClickListener(listener);
fl.addView(imageView);
fl.addView(imgoff);
tv=new TextView(getApplicationContext());
tv.setLayoutParams(new LayoutParams(116,20));
tv.setText(namesArr[i]);
tv.setTextColor(Color.BLACK);
rb=new RatingBar(getApplicationContext(),null,android.R.attr.ratingBarStyleSmall);
rb.setLayoutParams(new LayoutParams(80,50));
rb.setIsIndicator(true);
rb.setNumStars(5);
rb.setRating(rateFArr[i]);
layout.addView(fl);
layout.addView(tv);
layout.addView(rb);
layout.setOnClickListener(listener);
return layout;
}
請有人可以幫我解決這個問題。提前致謝。
rb = new RatingBar(getApplicationContext(),null,R.Style.ratingbar_red);仍然沒有制定出評級欄本身消失。我甚至檢查了佈局大小都很好。 – user2609258
嗨,周杰倫,我試過這個解決方案,但是當我嘗試將評分設置爲1.1,1.2等等時,它顯示爲1.5。我拍攝了3張明星影像,一張是空的,一張是滿的,另一張是滿的。我認爲它應該在它們之間進行插值以獲得小數部分,我只是想知道是否有其他人有同樣的問題,或者我在做什麼明顯錯誤? –
這個答案幫了我很多!謝謝你,先生! – JozeRi