【问题标题】:Custom RatingBar not showing more than 1 star自定义 RatingBar 未显示超过 1 星
【发布时间】:2016-12-20 16:48:36
【问题描述】:

我已经从 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>

【问题讨论】:

    标签: android android-layout android-xml ratingbar


    【解决方案1】:

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

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

    【讨论】:

    • 你认为他为什么使用SVG
    • @VladMatvienko 因为 OP 已经写了这个问题。很抱歉是Vector Drawable
    • 谢谢。它起作用了。我想知道 Vector Drawable 有什么问题。
    • @DilipAti 很高兴为您提供帮助。
    • 非常感谢,真的是矢量可绘制的问题
    猜你喜欢
    • 1970-01-01
    • 2015-05-23
    • 1970-01-01
    • 1970-01-01
    • 2012-09-05
    • 2011-04-20
    • 1970-01-01
    • 1970-01-01
    • 2011-11-26
    相关资源
    最近更新 更多