Android 评分栏布局权重 属性 行为不正常

Android Rating Bar layout weight property not behaving properly

我在 LinearLayout 中有一个 TextViewRatingBar 水平方向。

我想在最左边的区域设置TextView,在最右边的区域设置RatingBar。所以我给 LinearLayout 一个权重和以及这两个视图,以便稍后我可以给它们 layout_gravity leftend

但问题是当我给出评级条时 layout_weight 它正在增加或减少其评级条数。我已将评级栏编号设置为固定,但仍然无法正常工作。那么如何为 RatingBar 设置 layout_weight

我的代码:

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:weightSum="10">
        <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_weight="3"
        android:layout_marginLeft="10sp"
        android:textSize="20sp"
        android:text="Service"/>
        <RatingBar
        android:id="@+id/rbAddFoodItemRatingDialog"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        style="?android:attr/ratingBarStyleIndicator"
        android:numStars="5"
        android:max="5"
        android:layout_weight="7"
        android:theme="@style/RatingBar"
        android:rating="3.5"/>
</LinearLayout>

这个 XML 布局给我 7 个评级栏而不是 5 个栏!这有什么问题吗?

将其包裹在线性布局中并为其设置权重

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:weightSum="10">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_weight="3"
        android:layout_marginLeft="10sp"
        android:textSize="20sp"
        android:text="Service"/>

    <LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_weight="7">

        <RatingBar
            android:id="@+id/rbAddFoodItemRatingDialog"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            style="?android:attr/ratingBarStyleIndicator"
            android:numStars="5"
            android:max="5"
            android:theme="@style/RatingBar"
            android:rating="3.5"/>

    </LinearLayout>
</LinearLayout>