我發現自己在這裏有點困惑。我對android/java開發相當陌生,所以請在這裏幫助確定我做錯了什麼。我在整個谷歌,安卓開發和堆棧中積極地進行了檢查,但是在這方面找不到太多信息。Android ratingbar「ratingBarStyleSmall」載入隨機數量的星星
我有一個數字作爲theRating的字符串變量。例如2.5(滿分爲10) 我想顯示這個使用ratingbarstylesmall ...它只顯示,而不是評級。
RatingBar rb = new RatingBar(this, null, android.R.attr.ratingBarStyleSmall);
rb.setIsIndicator(true);
rb.setNumStars(5);
rb.setStepSize((float) 0.5);
rb.setMax(10);
rb.setRating(Integer.parseInt(theRating));
llTextEtc.addView(rb);
星星加載內LienarLayout(llTextEtc)的罰款,在正確的地方展現出來,這是我想要的(小)合適的款式明星,但...
它是完全隨機的。有些顯示8顆星,有些顯示15顆,然後是7顆,等等。完全隨機的。我究竟做錯了什麼?
謝謝你們
更新: 與接受的答案幫助:加入 一個的LinearLayout將與WRAP_CONTENT佈局的RatingBar。否則,父(scrollview)變成wrap_content。
LinearLayout llRating = new LinearLayout(this);
RatingBar rb = new RatingBar(this, null, android.R.attr.ratingBarStyleSmall);
rb.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
rb.setIsIndicator(true);
rb.setNumStars(5);
rb.setRating(Float.parseFloat(theRating)/2);
llRating.addView(rb);
llTextEtc.addView(llRating);
setStepSize和setMax也被刪除,Rating被設置爲float而不是整數。星星計算並設置。當isIndicator爲true時,stepSize和Max不起作用。
'theRating'從哪裏來? – FoamyGuy
*「在整個谷歌中大力檢查」*我聽說過「貪婪搜索」,但什麼是「積極搜索」?作爲一般性提示「不要生氣」。 ;) –
@Tim theRating來自分割成數組的URL供稿。 theRating = feedArray [4]; -AndrewThompson哈哈 - 積極的很多短語和關鍵詞和憤怒。好的一個 – Onimusha