[英]Android RatingBar can't set rating
我正在嘗試在我的Android應用中實現RatingBar,但是在嘗試設置評分時遇到了一些問題。 我的酒吧始終顯示為具有最高可用評分。 以下是我的文件:
styles.xml
<style name="ratingBarStyling" parent="@android:style/Widget.RatingBar">
<item name="android:progressDrawable">@drawable/star_rating_bar</item>
<item name="android:indeterminateDrawable">@drawable/star_rating_bar</item>
<item name="android:minHeight">25dip</item>
<item name="android:maxHeight">27dip</item>
</style>
(與v21相同)
star_rating_bar.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/background"
android:drawable="@drawable/star_rating_bar_full_empty" />
<item android:id="@+id/secondaryProgress"
android:drawable="@drawable/star_rating_bar_full_empty" />
<item android:id="@+id/progress"
android:drawable="@drawable/star_rating_bar_full_filled" />
</layer-list>
star_rating_bar_full_empty
<?xml version="1.0" encoding="utf-8"?>
<selector
xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true"
android:state_window_focused="true"
android:drawable="@drawable/ic_star_empty" />
<item android:state_focused="true"
android:state_window_focused="true"
android:drawable="@drawable/ic_star_empty" />
<item android:state_selected="true"
android:state_window_focused="true"
android:drawable="@drawable/ic_star_empty" />
<item android:drawable="@drawable/ic_star_empty" />
</selector>
star_rating_bar_full_filled
<?xml version="1.0" encoding="utf-8"?>
<selector
xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true"
android:state_window_focused="true"
android:drawable="@drawable/ic_star" />
<item android:state_focused="true"
android:state_window_focused="true"
android:drawable="@drawable/ic_star" />
<item android:state_selected="true"
android:state_window_focused="true"
android:drawable="@drawable/ic_star" />
<item android:drawable="@drawable/ic_star" />
</selector>
最后是Fragment布局上的RatingBar的實現:
<RatingBar
style="@style/ratingBarStyling"
android:id="@+id/venue_card_rating"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="20dp"
android:numStars="5"
android:stepSize="1.0"
android:rating="2.0"/>
現在由於某種原因,我可以看到填充的星形圖標,但看不到空的星形圖標。 我也嘗試過以編程方式設置它,但是結果是相同的。 任何幫助將不勝感激。
這就是我一直得到的: stars.png
您犯了小錯誤/輸入錯誤,您將不得不使用android:id而不是提供新的ID。
<?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_rating_bar_full_empty" />
<item android:id="@android:id/secondaryProgress"
android:drawable="@drawable/star_rating_bar_full_empty" />
<item android:id="@android:id/progress"
android:drawable="@drawable/star_rating_bar_full_filled" />
</layer-list>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.