安卓定制的RatingBar图像伪影图像、RatingBar

2023-09-12 09:48:11 作者:丑人多作怪

我在一个应用程序中实现我的的ListView 项自定义的RatingBar 。 自定义风格的 ratingbar_red.xml

I implemented a custom RatingBar in an application on my ListView items. Custom style ratingbar_red.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_off" />
    <item android:id="@android:id/secondaryProgress" android:drawable="@drawable/star_on" />
    <item android:id="@android:id/progress" android:drawable="@drawable/star_on" />
</layer-list>

下面是一个ListItem布局的一部分:

Here's part of ListItem layout:

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:paddingLeft="15dp" >

    <RatingBar
        android:id="@+id/li_company_rating"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="15dp"
        android:layout_marginBottom="1dp"
        android:isIndicator="true"
        android:numStars="5"
        android:progressDrawable="@drawable/ratingbar_red"
        android:stepSize="1" />

    <Button
        android:id="@+id/li_company_callbtn"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="0dp"
        android:layout_marginLeft="40dp"
        android:contentDescription="@string/ContentDescription"
        android:drawableLeft="@drawable/phone_icon"
        android:drawablePadding="5dp"
        android:onClick="callbtn_Click"
        android:text="@string/CallButton"
        android:focusable="false"
        android:focusableInTouchMode="false" >
    </Button>

</LinearLayout>

它的工作原理,但是当等级设置,我得到一些奇怪的图像失真;下面的粉红色的星星2的垂直线出现在我的看法:

It works, but when the rating is set, I get some strange image artifacts; 2 vertical lines below the pink stars appear on my view:

下面是 star_on.png

star_off.png 看起来不错,如果评级== 0,该线不会出现。

star_off.png looks okay, and if rating == 0, the lines don't appear.

我是android的初学者,不明白是什么问题。

I'm android beginner, and can't understand what the problem is.

推荐答案

尝试与以的RatingBar 给予高度XML布局是这样的:

try with giving height to RatingBar in xml layout like this:

android:layout_height="30sp" 

30sp或任何适合你..

30sp or whatever suits you..

看看为什么会这样?