给 RatingBar 添加边距/内边距

3

我有一个评分条的图片,就像这样:

enter image description here

现在,我想知道如何为评分条中的每一项添加边距或填充?

styles.xml

<resources>
<style name="starRatingBar" parent="@android:style/Widget.RatingBar">
    <item name="android:progressDrawable">@layout/starratingbar_full</item>
    <item name="android:minHeight">19dp</item>
    <item name="android:maxHeight">19dp</item>
</style>
</resources>

starratingbar_full.xml

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="20dp"
android:layout_width="30dp">

<item android:id="@+android:id/background"
    android:drawable="@drawable/starunselected"
    />
<item android:id="@+android:id/secondaryProgress"
    android:drawable="@drawable/starunselected" />
<item android:id="@+android:id/progress"
    android:drawable="@drawable/starselected" />
</layer-list>

activity.xml

<RatingBar
style="@style/starRatingBar"
android:numStars="5"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:id="@+id/ratingBar"
android:layout_marginLeft="130dp"
android:layout_marginTop="88dp"
android:stepSize="1"/>

有人能帮忙吗?

可能是评分条的星星之间的间距?的重复问题。 - siriscac
2个回答

3

使用任何Photoshop或编辑器,您可以简单地在PNG的左右两侧添加一些空白空间。


2
如果您正在使用Drawable来表示星级,请确保您的Drawable具有左侧填充,以满足您的要求。 否则通过代码实现将无法正常工作。几天前我也遇到了同样的问题,通过使用左填充图像解决了这个问题。希望它能起作用。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接