android - 自定义 RatingBar 未显示超过 1 星

标签 android android-layout android-xml ratingbar

我已经从 this stackoverflow thread 实现了自定义评级栏即使我将 numStars 设置为 5 或任何其他数字

,它也不会显示超过一颗星

这是代码。

我正在为图像使用矢量绘图。

ma​​in_activity.xml 中的 RatingBar

<RatingBar
        android:id="@+id/ratingBarValue"
        style="@style/Fuel_Indicator"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:numStars="5"
        android:stepSize="1.0"
        android:max="5" />

Fuel_Indicator 样式中的样式。

<style name="Fuel_Indicator" parent="@android:style/Widget.RatingBar">
    <item name="android:progressDrawable">@drawable/fuel_bar_full</item>
    <item name="android:indeterminateDrawable">@drawable/fuel_bar_full</item>
    <item name="android:minHeight">23dip</item>
    <item name="android:maxHeight">25dip</item>
</style>

fuel_bar_filled.xml

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

fuel_bar_empty.xml

<selector
xmlns:android="http://schemas.android.com/apk/res/android">`
<item android:state_pressed="true"
    android:state_window_focused="true"
    android:drawable="@drawable/ic_fuel_empty" />

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

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

<item android:drawable="@drawable/ic_fuel_empty" />
</selector>

fuel_bar_filled.xml

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

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

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

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

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

</selector>

最佳答案

您的实现是完美的但是您使用的 Vector Drawable 导致了这个问题。因此,要使用它,请尝试将 drawable 文件夹中的 Vector Drawable 替换为 png 图像,看看它的神奇之处。

您将 Vector Drawablelayer-list 一起使用,因此您的 Vector Drawable 图像适合整个布局尝试将其替换为 png 这将解决您的问题。

关于android - 自定义 RatingBar 未显示超过 1 星,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41237324/

相关文章:

android - 将 MountSpec 组件与 "wrap_content" View 一起使用 - 如何实现 onMeasure()

android - 在底部对齐 RecyclerView 中的项目

java - Android中的动态与XML布局?

javascript - 开发离线 MathJax Android 移动应用程序

Android股票浏览器不尊重CSS溢出

java - 将 Activity 元素的排列设置为从左到右(默认)

Android:为按钮添加 NEON 效果

iphone - 使用超声波传输数据

安卓数据绑定(bind): how to get useful error messages

Android:用对象填充 ListView