Question

I just want to have a RatingBar with 5 stars in a TableRow but it always come out 8 stars. but I have already used android:numStars="5" to notify it.

Also, it fills 7.5 star instead of 4 stars with android:rating="4" whatever I have changed just meaningless to the layout.

My XML is as follow:

<?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>
Was it helpful?

Solution

Here you are using the rating bar inside table row. According to reference docs the children of tablerow take match parent as their width. So instead you can nest a horizontal linearlayout inside this table row which in turn will embed rating bar as follows :

<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>

OTHER TIPS

            style="?android:attr/ratingBarStyleSmall"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:isIndicator="true"
            android:numStars="5"
           android:stepSize="1.0" />
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top