rating - Android RatingBar numStart 不起作用

标签 rating ratingbar

我的应用程序中有简单的 RatingBar。我设置了 numStarts="5" 但它显示超过 5 星。当我设置 ndroid:layout_width="match_parent" 时,我尝试了几个教程,但也没有用,根据 numStarts doc 显示启动次数,但在我的情况下,它不起作用。我浏览了 doc 和几个教程,但没有得到任何解决方案。

enter image description here

但我只想在评级栏中给 5 星。

我的评分栏如下。

<RatingBar
    style="@style/customRatingBar"
    android:id="@+id/course_rating_bar"
    android:layout_height="match_parent"
    android:layout_width="match_parent"
    android:layout_marginRight="16dp"
    android:layout_marginLeft="16dp"
    android:numStars="5"
    android:isIndicator="false"
    android:stepSize="1.0"/>

这是我的自定义样式
<style name="foodRatingBar" parent="@android:style/Widget.RatingBar">
        <item name="android:progressDrawable">@drawable/ratingstars</item>
        <item name="android:minHeight">22dip</item>
        <item name="android:maxHeight">22dip</item>
    </style>

......
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:id="@+android:id/background"
        android:drawable="@drawable/star_empty" />
    <item android:id="@+android:id/secondaryProgress"
        android:drawable="@drawable/star_empty" />
    <item android:id="@+android:id/progress"
        android:drawable="@drawable/star" />
</layer-list>

最佳答案

你必须设置 android:layout_width="wrap_content"而不是 "match_parent"。然后你会得到5星。

关于rating - Android RatingBar numStart 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32264414/

相关文章:

html - 简单的评级星 CSS

android - 如何在 TextView 中显示评分栏值

rating - 作为程序员,您如何衡量自己的技能?

jquery - 星级评分系统在点击时保存值(value),仅将值(value)保存在数据库中

快速评级系统循环和分配

wordpress - 你如何在woocommerce中为产品添加星级?

Android如何增加评分栏中星星的高度和宽度

php - 当 Wilson 分数间隔相等时,MYSQL 使用 UploadDate 对下一行进行排序

android - ListView 中的评级栏评级重置

android - 评级栏不工作