【问题标题】:Problems with Android's RatingBarAndroid 的 RatingBar 问题
【发布时间】: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>

【问题讨论】:

    标签: android rating


    【解决方案1】:

    我遇到了同样的问题...它与您部署到的最小版本和屏幕尺寸有关。

    我解决了它在 android manifest 中手动设置支持的屏幕尺寸:

    <supports-screens android:smallScreens="true" 
          android:normalScreens="true" 
          android:largeScreens="true" 
          android:anyDensity="true" />
    

    希望对你有帮助。

    编辑:

    我实际上回答了同样的问题here.

    您需要做的就是将布局宽度设置为 wrap_content

    【讨论】:

    • 所以我猜,它与屏幕尺寸有关。但是,minVersion = 8,并且支持屏幕也在清单中:(
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-03-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多