评分栏不能只显示满星

ratingbar cannot show only full stars

我试图在评分栏中仅显示 10 颗星。但是当我点击评分时,没有显示全星

<RatingBar
    android:id="@+id/ratingBar"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:numStars="10"
    android:stepSize="1.0"
    android:max="10"
    android:layout_weight="1" />

问题在于视图的宽度。我把它弄乱了一点,似乎 10 颗星太宽了,屏幕上放不下它们。这弄乱了视图。如果您尝试将其置于横向模式,您会发现它可以正常工作。您要么必须在横向模式下执行此操作,要么使用更少或更小的星星,以便它们适合屏幕的宽度。

试试这个。

RatingBar星号默认更大

RatingBar

中使用style="@style/Widget.AppCompat.RatingBar.Small"

删除android:layout_weight="1"

<RatingBar
    android:id="@+id/ratingBar"
    style="@style/Widget.AppCompat.RatingBar.Small"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:numStars="10"
    android:rating="2.5"
    android:stepSize=".5"/>

RatingBar 中的星星不会通过 Android.Use 评级栏中的自定义样式来调整评级栏的大小。

<style name="MyRatingBar" parent="@android:style/Widget.DeviceDefault.RatingBar.Indicator">
    <item name="android:minHeight">48dp</item>
    <item name="android:maxHeight">48dp</item>
</style>

然后将该样式添加到评分栏

<RatingBar
    android:id="@+id/ratingBar"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:numStars="10"
    android:stepSize="1.0"
    android:max="10"
    style="@style/MyRatingBar"  />

有关此问题的更多信息,请在此处查看 http://web.archive.org/web/20160323223259/http://kozyr.zydako.net/2010/05/23/pretty-ratingbar/