gpt4 book ai didi

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

转载 作者:可可西里 更新时间:2023-11-01 18:58:12 34 4
gpt4 key购买 nike

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

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com