我得到的星星比视图中指定的要多

I am getting more stars than specified in the view

我想在我正在使用的布局中使用 RatingBar。它应该包含最多 5 颗星。现在的问题是,当我使用下面发布的代码时,我得到一个 RatingBar 超过 5 颗星

我想知道我应该如何修改下面的成本视图,以便我可以使用恰好 5 开始

代码:

<RatingBar
      android:id="@+id/cardViewRatingBar"
      android:layout_width="0dp"
      android:layout_height="wrap_content"
      android:layout_weight="3"
      android:numStars="5"
      android:rating="4"
      android:stepSize=".5"
      style="?android:attr/ratingBarStyleSmall"/>

我相信您的问题可能与布局宽度有关。我不认为 ratingBar 可以成功设置为 "wrap_content" 以外的任何值,否则你会遇到你所描述的问题。

试试这个:

<RatingBar
      android:id="@+id/cardViewRatingBar"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:numStars="5"
      android:rating="4"
      android:stepSize=".5"
      style="?android:attr/ratingBarStyleSmall"/>

因此,您可能需要对父布局做一些工作才能在 activity 中按照您的意愿进行设置,或者您可以尝试对栏进行不同的样式设置。