0

编辑: 我删除了该行

<item
    android:id="@+android:id/secondaryProgress"
    android:drawable="@drawable/ratingbar_full_empty_sc"/>

它消除了不良影响。所以这确实是一个超级问题。现在给半分的感觉是很笨拙的。有人有真正的解决方案吗?请...

原帖

我尝试实现一个评级栏,但我对半满的有一些问题。我修改现有代码并关注这篇文章

这是奇怪的结果:

评分栏 - 注意半满星周围较暗的笔划

听说过这个问题吗?

我在下面发布我的代码

 <RatingBar
            android:id="@+id/rating_view"
            style="@style/sc_rating_bar"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="@dimen/padding_medium" />

评分栏样式:

    <style name="sc_rating_bar" parent="@android:style/Widget.RatingBar">
    <item name="android:progressDrawable">@drawable/ratingbar_full_sc</item>
    </style>

进度绘图:

<?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/ratingbar_full_empty_sc"/>
<item
    android:id="@+android:id/secondaryProgress"
    android:drawable="@drawable/ratingbar_full_empty_sc"/>
<item
    android:id="@+android:id/progress"
    android:drawable="@drawable/ratingbar_full_filled_sc"/>

</layer-list>

ratingbar_full_empty_sc :

<selector xmlns:android="http://schemas.android.com/apk/res/android">

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

</selector>

而他的兄弟 ratingbar_full_filled_sc 和 image 完全一样star_full2

我做错了什么 ?你可以在我的截图上看到两张图片,一张是满的星,一张是空的。

4

1 回答 1

0

啊啊 !根据我之前的编辑,我找到了一个小解决方案:在progressDrawable我修改secondaryProgress

    <item
    android:id="@+android:id/secondaryProgress"
    android:drawable="@drawable/ratingbar_full_null_sc"/>

顾名思义,我在里面放了一个可绘制的空图像:

<selector xmlns:android="http://schemas.android.com/apk/res/android">

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

</selector>

指的@drawable/star_empty2_null是一个图像,与填充星和空星大小相同,但其中没有任何内容(我拿了星形文件,在 Gimp 中将其清除并以相同的像素大小导出)。

完美流畅的动画,不再有视觉叠加!

于 2013-11-29T16:39:14.437 回答