Android 表行中的ratebar星

Android 表行中的ratebar星,android,rate,Android,Rate,我只想要一个在表格行中有5颗星的评级条,但它总是有8颗星。 但是我已经使用了android:numStars=“5”来通知它 此外,它用android:rating=“4” 无论我改变了什么,对布局都毫无意义 我的XML如下所示: <?xml version="1.0" encoding="utf-8"?> <TableLayout xmlns:android="http://schemas.android.com/apk/res/android" an

我只想要一个在
表格行中有5颗星的
评级条
,但它总是有8颗星。 但是我已经使用了
android:numStars=“5”
来通知它

此外,它用
android:rating=“4”
无论我改变了什么,对布局都毫无意义

我的XML如下所示:

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

        <TableRow
            android:id="@+id/image_row"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:gravity="center"
            android:padding="5dp" >

            <ImageView
                android:id="@+id/grid_image"
                android:layout_width="130dp"
                android:layout_height="130dp" />

        </TableRow>

        <TableRow
            android:id="@+id/text_row"
            android:layout_width="wrap_content"
            android:layout_height="70dp" 
            >

            <TextView
                android:id="@+id/grid_text"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:maxWidth="140dp"
                android:text="Summary" />

        </TableRow>

        <TableRow
            android:id="@+id/rate_row"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" >

            <RatingBar
                android:id="@+id/product_rating"
                style="?android:attr/ratingBarStyleSmall"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:isIndicator="true"
                android:max="5"
                android:numStars="5"
                android:rating="4"
                android:stepSize="1" />

        </TableRow>

    </TableLayout>


在这里,您使用的是表行内的评级栏。根据参考文档,tablerow的子级将匹配父级作为其宽度。因此,您可以在该表行中嵌套一个水平线性布局,该布局将嵌入评级栏,如下所示:

<TableRow
        android:id="@+id/rate_row"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" >

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" >

            <RatingBar
                android:id="@+id/product_rating"
                style="?android:attr/ratingBarStyleSmall"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:isIndicator="true"
                android:max="5"
                android:numStars="5"
                android:rating="4"
                android:stepSize="1" />
        </LinearLayout>
    </TableRow>

<TableRow
        android:id="@+id/rate_row"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" >

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" >

            <RatingBar
                android:id="@+id/product_rating"
                style="?android:attr/ratingBarStyleSmall"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:isIndicator="true"
                android:max="5"
                android:numStars="5"
                android:rating="4"
                android:stepSize="1" />
        </LinearLayout>
    </TableRow>