Lollipop下面的Android RatingBar渲染错误

时间:2015-06-10 10:27:26

标签: ratingbar

enter image description here

enter image description here

我正在使用自定义评级栏。五星级的顶级图像在Lollipop上,我的评级栏工作正常。然而,在Lollipop(Kitat,JellyBean,ICS)版本之下,评级栏已经过时了(用一颗星查看第二张图片) 可能是什么问题?我尝试了所有可能的方法,改变主题,管理高度宽度......似乎没有任何作用:(

这是风格

<style name="customRatingBar" parent="@android:style/Widget.RatingBar">

    <item name="android:progressDrawable">@drawable/rating_custom_bar</item>

</style>

这是评级栏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_blank"/>
    <item
        android:id="@+android:id/secondaryProgress"
        android:drawable="@drawable/star_blank"/>
    <item
        android:id="@+android:id/progress"
        android:drawable="@drawable/star_filled"/>
</layer-list>

这是空白

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">

    <item android:drawable="@drawable/rating_empty" android:state_pressed="true" android:state_window_focused="true"/>
    <item android:drawable="@drawable/rating_empty" android:state_focused="true" android:state_window_focused="true"/>
    <item android:drawable="@drawable/rating_empty" android:state_selected="true" android:state_window_focused="true"/>
    <item android:drawable="@drawable/rating_empty"/>

</selector>

这是明星填充

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">

    <item android:drawable="@drawable/rating_full" android:state_pressed="true" android:state_window_focused="true"/>

    <item android:drawable="@drawable/rating_full" android:state_focused="true" android:state_window_focused="true"/>

    <item android:drawable="@drawable/rating_full" android:state_selected="true" android:state_window_focused="true"/>

    <item android:drawable="@drawable/rating_full"/>

</selector>

2 个答案:

答案 0 :(得分:0)

我遇到同样的问题,花了很多时间,尝试在ratingBar设置所有参数但没有工作,但有些奇怪。我和一个朋友在一个项目中工作,他编译与我完全相同的代码并且没有这个问题,因此我将IDE更改为他并且所有人都开始工作。

我使用的是“Android开发者工具”,这是您在https://developer.android.com/training/index.html下载的eclipse,这是一个已经嵌入ADT的日食。 我按照说明http://developer.android.com/sdk/installing/installing-adt.html

更改为Java EE并下载ADT

我希望这可以帮助您解决问题。

答案 1 :(得分:-2)

已经有一段时间但从不伤害回答。这是我的3步解决方案,无论SDK版本如何。

1-在xml布局中将其添加为RatingBar:

<RatingBar
android:id="@+id/new_ratingbar"
android:progressDrawable="@drawable/custom_drawable" 
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:numStars="5"
android:stepSize="0.5"/>

如果需要,您可以给出RatingBar minHeight和maxHeight,或者根据需要添加其他属性。

2-这是drawable,你可以将上面的progressDrawable引用到:

<强> custom_drawable.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/rating_bar_empty" /> <!--this is your .png file-->
    <item
        android:id="@android:id/secondaryProgress"
        android:drawable="@drawable/rating_bar_fill" /> <!--this is your .png file-->
    <item
        android:id="@android:id/progress"
        android:drawable="@drawable/rating_bar_fill" /> <!--this is your .png file-->
</layer-list>

3-最后一件事是在各种可绘制文件夹中提供.png文件。