我已經創建了我的自定義樣式RatingBar following http://kozyr.zydako.net/2010/05/23/pretty-ratingbar/這完美的當我在我的XML文件中聲明我的RatingBar。不過,我還需要在我的Java代碼來創建動態ratingbars,這是我做的:RatingBar自定義樣式不顯示
for (int i=0; i<Math.min(10, n); i++){
TableRow row = new TableRow(RegisterActivity.this);
TextView t = new TextView(RegisterActivity.this);
t.setText((i+1) + ". " + myCList.get(i) + "/" + myWList.get(i) + " (" + mySList.get(i) + ")");
RatingBar c = new RatingBar(RegisterActivity.this, null, R.style.foodRatingBar);
Double d=(Double) myRList.get(i);
c.setRating(d.floatValue());
c.setClickable(false);
row.addView(t);
row.addView(c);
table.addView(row,new TableLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
}
的問題是,ratingbars不顯示,當我以這種方式使用它們。這是我的自定義樣式:
<style name="foodRatingBar" parent="@android:style/Widget.RatingBar">
<item name="android:progressDrawable">@drawable/food_ratingbar_full</item>
<item name="android:minHeight">50dp</item>
<item name="android:maxHeight">50dp</item>
</style>
當我使用標準小樣式作爲ratingbars時,相同的過程可以很好地工作。有人知道爲什麼嗎?
它看起來像R.style.foodRatingBar(或任何其他自定義樣式)不被RatingBar構造函數識別,而標準的android.R.attr.ratingbarsmall是。這看起來很奇怪! – splinter123