Android 自定义 RatingBar 图片神器 [英] Android custom RatingBar image artifacts

查看:28
本文介绍了Android 自定义 RatingBar 图片神器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的 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 看起来不错,如果 rating == 0,则不会出现线条.

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

我是安卓初学者,不明白问题出在哪里.

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

推荐答案

尝试在 xml 布局中为 RatingBar 提供高度,如下所示:

Try giving height to RatingBar in xml layout like this:

android:layout_height="30dp" 

30dp 或任何适合您的..

30dp or whatever suits you..

看看为什么会这样??

这篇关于Android 自定义 RatingBar 图片神器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆