【发布时间】:2012-04-06 04:50:54
【问题描述】:
我正在尝试自定义一点 android 的 RatingBar。
我找到了一个 tutorial 来做这件事,但我有一个问题。
我将评分栏 numStars 的属性设置为 5。
我得到的是,评分栏的每个“星”都将代表我的三个。
我在本教程的 cmets 中读到,有人遇到了类似的问题,但没有解决该问题的方法。
有人可以在 Android 2.2 上尝试本教程吗?或者推荐其他教程?
提前谢谢你
UPD:
这是我的一些代码:
res/drawable/star_selector_full_filled.xml:
<?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/star_highlighted" />
<item android:state_focused="true"
android:state_window_focused="true"
android:drawable="@drawable/star_highlighted" />
<item android:state_selected="true"
android:state_window_focused="true"
android:drawable="@drawable/star_highlighted" />
<item android:drawable="@drawable/star_highlighted" />
</selector>
res/drawable/star_selector_empty.xml:
<?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/star_white" />
<item android:state_focused="true"
android:state_window_focused="true"
android:drawable="@drawable/star_white" />
<item android:state_selected="true"
android:state_window_focused="true"
android:drawable="@drawable/star_white" />
<item android:drawable="@drawable/star_white" />
</selector>
res/drawable/star_selector.xml:
<?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_selector_empty" />
<item android:id="@+android:id/secondaryProgress"
android:drawable="@drawable/star_selector_empty" />
<item android:id="@+android:id/progress"
android:drawable="@drawable/star_selector_full_filled" />
</layer-list>
res/values/styles.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="starRatingBar" parent="android:style/Widget.RatingBar">
<item name="android:progressDrawable">@drawable/star_selector</item>
<item name="android:minHeight">25dip</item>
<item name="android:maxHeight">25dip</item>
</style>
</resources>
【问题讨论】: