小编Dil*_*Ati的帖子

自定义RatingBar未显示超过1星

我已经从这个stackoverflow线程实现了一个自定义评级栏,即使我将numStars设置为5或任何其他数字,它也不会显示多个星号

这是守则.

我正在使用矢量绘图用于图像.

main_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" />
Run Code Online (Sandbox Code Playgroud)

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>
Run Code Online (Sandbox Code Playgroud)

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" />
Run Code Online (Sandbox Code Playgroud)

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>
Run Code Online (Sandbox Code Playgroud)

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 …
Run Code Online (Sandbox Code Playgroud)

android android-layout android-xml ratingbar

15
推荐指数
1
解决办法
2968
查看次数

标签 统计

android ×1

android-layout ×1

android-xml ×1

ratingbar ×1