【问题标题】:ratebar star in tablerow表格中的评分栏星
【发布时间】:2014-04-24 06:59:48
【问题描述】:

我只想在TableRow 中有一个 5 星的 RatingBar,但它总是得到 8 星。 但是我已经用android:numStars="5"通知了。

此外,它使用android:rating="4" 填充 7.5 星而不是 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>

【问题讨论】:

    标签: android rate


    【解决方案1】:

    在这里,您使用的是表格行内的评分栏。根据参考文档,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>
    

    【讨论】:

      【解决方案2】:

                  style="?android:attr/ratingBarStyleSmall"
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content"
                  android:isIndicator="true"
                  android:numStars="5"
                 android:stepSize="1.0" />
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-06-20
        • 2016-09-23
        • 1970-01-01
        • 1970-01-01
        • 2021-02-06
        相关资源
        最近更新 更多