[英]How to assign Rating value in Ratingbar in android?
I need to give rating for a product where everything comes dynamically. 我需要给所有动态产生的产品评分。
String rating = i.getStringExtra("Rating"); // the output of string is 8.6
RatingBar txtrating = (RatingBar)findViewById(R.id.rating);
txtrating.setRating(Float.parseFloat(rating));
This gives 29 stars rated fully. 这使29星获得了完全的评价。 But i need to give 10 stars where 8.6 should be assigned.
但是我需要给10颗星分配8.6。
xml is as follows: xml如下:
<RatingBar
android:id="@+id/rating"
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="?android:attr/ratingBarStyleSmall"
android:numStars="10" // don't know why many stars are reproducing.
android:isIndicator="true" />
From documentation : 从文档 :
The number of stars set (via
setNumStars(int)
or in an XML layout) will be shown when the layout width is set to wrap content (if another layout width is set, the results may be unpredictable).当设置布局宽度以包装内容时,将显示(通过
setNumStars(int)
或在XML布局中)设置的星形数(如果设置了另一个布局宽度,则结果可能无法预测)。
Basically the widget repeats stars indefinitely and you need to set android:layout_width="wrap_content"
so it respects the android:numStars="10"
attribute. 基本上,小部件会无限期地重复出现星星,您需要设置
android:layout_width="wrap_content"
以便它尊重android:numStars="10"
属性。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.