这是我第一次使用android中的 Rating Bars 。 我有一个自定义的评分栏,其外观应为like this(很抱歉,我没有将图片完整显示的声誉。 所有五个空星看起来都应该是as you can see here,但实际上,当我滚动以进行评分时,满星变成like this。 以下是我到目前为止编码的代码:
可绘制对象custom_ratingbar
:
<?xml version="1.0" encoding="UTF-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@android:id/background" android:drawable="@drawable/star_empty" />
<item android:id="@android:id/secondaryProgress" android:drawable="@drawable/star_empty" />
<item android:id="@android:id/progress" android:drawable="@drawable/star_full" />
</layer-list>
在我的styles.xml
中:
<style name="StarRatingBar" parent="@android:style/Widget.RatingBar">
2
<item name="android:progressDrawable">@drawable/custom_ratingbar</item>
3
<item name="android:minHeight">48dip</item>
4
<item name="android:maxHeight">48dip</item>
5
</style>
最后,在我的fragment_upload_photo.xml
中:
<RatingBar
android:id="@+id/ratingBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="@style/StarRatingBar"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:layout_marginBottom="135dp"
android:layout_marginEnd="83dp"
android:numStars="5"
android:stepSize="1" />
您知道我怎样才能使评级工作正常吗?就像我告诉你的那样,这是我第一次弄乱评分栏,因此先前提到的所有XML代码都是从StackOverflow
中另一个问题中复制过来的。