1

我正在尝试编写代码,当我获得 Rating 的整数值时,我应该以 1 的步长更新评分。这是相同的代码

<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_gravity="center_vertical|center_horizontal"
android:layout_marginRight="3dp" >

    <RatingBar
    android:id="@+id/PriceRating"
    style="@style/foodRatingBarSmall"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:isIndicator="true"
    android:numStars="1"
    android:stepSize="0.25"
    android:max="5" />

</LinearLayout>

这是样式文件中的代码:

<style name="foodRatingBarSmall" parent="@android:style/Widget.RatingBar">
    <item name="android:progressDrawable">@drawable/foodratingbar_full</item>
    <item name="android:minHeight">20dip</item>
    <item name="android:maxHeight">20dip</item>
</style>

这是 foodratingbar 文件

<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
    <item android:id="@+id/background" android:drawable="@drawable/foodratingbar_fill"
    />
    <item android:id="@+id/secondaryProgress"
    android:drawable="@drawable/foodratingbar_fill" />
    <item android:id="@+id/progress" android:drawable="@drawable/foodratingbar_empty" />

</layer-list>

这是 foodratingbar_fill 的代码:

<?xml version="1.0" encoding="utf-8"?>

    <selector xmlns:android="http://schemas.android.com/apk/res/android">

        <item android:state_pressed="true"
        android:state_window_focused="true"
        android:drawable="@drawable/dollar" />

        <item android:state_focused="true"
        android:state_window_focused="true"
        android:drawable="@drawable/dollar" />

        <item android:state_selected="true"
        android:state_window_focused="true"
        android:drawable="@drawable/dollar" />

        <item android:drawable="@drawable/dollar" />

    </selector>

美元是png图像的地方

我的代码的问题是我无法让它更新到所需的星数,而且我看到在 android 上显示的星数的值很模糊。我想知道如何为 1 个评分显示 1 个美元的图像,最多为 5 个

4

0 回答 0