Android 分级栏不显示所有星星

Android 分级栏不显示所有星星,android,android-widget,android-styles,Android,Android Widget,Android Styles,我有这样的布局: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"&

我有这样的布局:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <RatingBar
        android:id="@+id/bar_detail_rating"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="0dp"
        android:isIndicator="true"
        android:max="10"
        android:numStars="10"
        android:padding="0dp"
        android:rating="7"
        android:scaleX="0.7"
        android:scaleY="0.7"
        android:stepSize="1" />

</LinearLayout>

对于android:max=10、android:numStars=10、android:stepSize=1,我希望它显示10颗星,并且通常在我通过setRating()的值的每单位大小上显示1颗星。但这并没有发生。我附上一个屏幕截图从Android工作室布局预览;这也正是我的Nexus5上显示的

它似乎在正确地计算它;如果评级为7,则为7/10星(即8 x 7/10=5.6星)加上阴影

在这里,我根本不知道问题出在哪里


只有0-5/5才是0-5/5这是7/10

<RatingBar
    android:id="@+id/bar_detail_rating"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:rating="3.5"
    />

评级栏中的星星似乎没有被Android调整大小;所以在我的例子中,只有7个空间。在景观布局中,我可以看到10颗星

调整星星的大小需要一些读数;但最终发现:

在我的例子中,诀窍是定义一种风格:

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

48dp
48dp

应用这种样式可以减少星星的大小并使其适合屏幕。

我认为android:scaleX=“0.7”android:scaleY=“0.7”。这两行可能会有问题。不,如果没有scaleX/scaleY,Android显示的8颗星会溢出视图边界。在0.7时,视图与屏幕完美契合。我认为ScaleX切断了你的一些星星,以解决问题。你可以使用自己的样式或自定义样式,如style=“?android:attr/ratingBarStyleSmall”