Android分级栏布局权重属性运行不正常

Android分级栏布局权重属性运行不正常,android,ratingbar,Android,Ratingbar,我在LinearLayout中有一个TextView和RatingBar,具有水平方向 我想在最左侧区域设置TextView,在最右侧区域设置RatingBar。因此,我给了线性布局一个权重和这两个视图,以便以后我可以给它们布局_重力左和结束 但问题是,当我给出评级条layou-weight时,它会增加或减少其评级条编号。我已经设置了固定的评级条编号,但仍然不起作用。那么,我如何设置分级栏的布局权重 我的代码: <LinearLayout android:layout_width=

我在
LinearLayout
中有一个
TextView
RatingBar
,具有水平方向

我想在最左侧区域设置
TextView
,在最右侧区域设置
RatingBar
。因此,我给了
线性布局
一个权重和这两个视图,以便以后我可以给它们
布局_重力
结束

但问题是,当我给出评级条
layou-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>


将其包装成线性布局,并设置重量?是的,我这样做就解决了这个问题。非常感谢:)