Android 的评级栏问题
我正在尝试自定义一些 Android 的评级栏。
我找到了一个 教程 来做到这一点,但我有一个问题。
我将评级栏 numStars 的属性设置为 5。
我得到的是,评级栏的每个“星星”将代表我的三个。
我在本教程的评论中读到,有人遇到了类似的问题,但该问题没有解决方案。
有人可以在 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>
I'm trying to customize a bit the android's RatingBar.
I found a tutorial to do that, but I have a problem.
I set property of rating bar numStars to 5.
What I get, that every 'star' of rating bar will be represented of three of mine.
I read in comments to this tutorial, that somebody's got the similar problem, but there is no solution for that problem.
Can somebody try this tutorial on Android 2.2? Or recommend another tutorial?
Thank you in advance
UPD:
And here is a bit of my code:
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>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我遇到了同样的问题...它与您部署的最小版本和屏幕尺寸有关。
我解决了这个问题,在 android 清单中手动设置支持的屏幕尺寸:
希望它有帮助。
编辑:
我实际上在这里回答了同样的问题。
您需要做的就是将布局宽度设置为wrap_content< /强>
I had the same problem... it has something to do with the min version you deploy to and the screen size.
I solved it manually setting the supported screen sizes in the android manifest:
Hope it helps.
Edit:
I actually answered this same problem here.
All you need to do is set the layout width to wrap_content