1

In my code I want set my custom stars but it didn't work properly

 <RatingBar
                android:id="@+id/ratingBar"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerInParent="true"
                android:numStars="5"
                android:stepSize="1"
                android:rating="1"
                android:progressDrawable="@drawable/rating_bar_color"/>

rating_bar_color.xml

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:id="@android:id/background" android:drawable="@drawable/starw30" />
    <item android:id="@android:id/progress" android:drawable="@drawable/star" />
</layer-list>

I use this code and what I got in result

enter image description here

Where the lines is coming from. The stars are the same size as default star size.

4

4 回答 4

4

出现这些行是因为您尝试使用android:layout_height="wrap_content". 因此,作为一种解决方案,您必须将评分栏的高度提供给图像的大小。

如果评分栏图像的大小为 20,则尝试添加

android:layout_height="20dip"

这对你有用!

于 2013-12-12T11:01:04.010 回答
1

只需尝试android:layout_height="20sp"或您使用的任何星号。

还有一件事,您需要为自定义评分栏定义样式:

例如:my_ratingbar.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="foodRatingBar" parent="@android:style/Widget.RatingBar">
        <item name="android:progressDrawable">@drawable/rating_bar_color</item>
        <item name="android:minHeight">36dip</item> 
        <item name="android:maxHeight">36dip</item>
    </style>
</resources>
<!--Where 36dp is the size of image and include progress drawable here.

使用以下方法将此样式应用于 RatingBar:

<RatingBar   
  ...
   style="@style/my_ratingbar" />
于 2013-12-12T10:50:34.660 回答
0

这个问题是由于图像的缩放不正确。解决这个问题的方法是遵循这样的比例比例..

低密度脂蛋白 | mdpi | tvdpi | 高清晰度电视 | xhdpi | xxhdpi | xxxhdpi

0.75 | 1 | 1.33 | 1.5 | 2 | 3 | 4

于 2015-01-02T07:26:55.037 回答
0

当星形资产的大小与评级栏的大小不同并且星形资产在星形本身和底部边框之间没有透明空间时,就会发生这些泄漏的星形。出于某种原因,android 试图通过复制资产的最低部分来放大图像,这样您就可以在资产底部添加一些透明空间,就像我在我的一个项目中所做的那样。

tl;dr:在明星资产下添加一些透明空间

于 2015-08-28T13:51:55.100 回答