如何让 RatingBar 显示五颗星 [英] How to make RatingBar to show five stars
问题描述
我正在遵循如何添加 RatingBar
的标准示例.为了控制星星的数量,我尝试使用 android:numStars="5"
.问题是星星的数量似乎根本没有任何作用.在纵向布局中,我得到 6 颗星,当我翻转手机时,我得到大约 10 颗星.我试图在加载 xml 的 Activity (myBar.setNumStars(5)
) 中设置星数,但该选项也没有成功.
I am following the standard example of how to add a RatingBar
. To control the number of stars I tried to use android:numStars="5"
. The problem is that the number of stars doesn't seem to do anything at all. In portrait-layout I get 6 stars and when I flip the phone I get about 10 stars. I tried to set the number of stars in my Activity (myBar.setNumStars(5)
) that loads the xml but there was no success with that option either.
所以我的问题是如何定义我的布局,使其只显示五颗星?设置 numStars
似乎不起作用.
So my question is how do I define my layout so that it will only show five stars? Set numStars
doesn't seem to work.
提前致谢,罗兰
推荐答案
<RatingBar
android:id="@+id/rating"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="?android:attr/ratingBarStyleSmall"
android:numStars="5"
android:stepSize="0.1"
android:isIndicator="true" />
在代码中
mRatingBar.setRating(int)
这篇关于如何让 RatingBar 显示五颗星的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!