android中的自定义评分栏不显示星星

时间:2018-12-13 09:51:30

标签: android xml ratingbar

因此,我试图制作一个自定义评分栏,并尝试遵循以下资源。

1)https://mobikul.com/android-changing-stars-rating-bar-images-like/
2)https://demonuts.com/android-custom-ratingbar/
3)How to create Custom Ratings bar in Android

但是,它们不起作用。下面是我的代码和输出的屏幕截图。

自定义评级栏窗口小部件以从可绘制对象中选取样式。

<RatingBar
            android:progressDrawable="@drawable/star_rating"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginStart="8dp"
            android:layout_marginTop="8dp"
            android:layout_marginEnd="8dp"
            android:layout_marginBottom="8dp"
            android:numStars="5"
            android:stepSize="1.0"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/suggestion" />

star_rating绘图对象

<item android:id="@android:id/background" android:drawable="@drawable/background" />
<item android:id="@android:id/secondaryProgress" android:drawable="@drawable/full_rating" />
<item android:id="@android:id/progress" android:drawable="@drawable/full_rating" />

完整等级的可绘制对象 在这里,我使用矢量可绘制对象而不是图像。

<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:height="24dp"
android:width="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path android:fillColor="#000" android:pathData="M12,17.27L18.18,21L16.54,13.97L22,9.24L14.81,8.62L12,2L9.19,8.62L2,9.24L7.45,13.97L5.82,21L12,17.27Z" />

背景可绘制 另一个可绘制的向量。

<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:height="24dp"
android:width="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path android:fillColor="#000" android:pathData="M12,15.39L8.24,17.66L9.23,13.38L5.91,10.5L10.29,10.13L12,6.09L13.71,10.13L18.09,10.5L14.77,13.38L15.76,17.66M22,9.24L14.81,8.63L12,2L9.19,8.63L2,9.24L7.45,13.97L5.82,21L12,17.27L18.18,21L16.54,13.97L22,9.24Z" />

现在我正在得到的输出。

Tablet Emulator screenshot

0 个答案:

没有答案
相关问题