将保证金/填充添加到RatingBar

时间:2022-09-25 18:00:44

I have an image of a rating bar like this:

我有一个评级栏的图像,如下所示:

将保证金/填充添加到RatingBar

Now, I would like to know how would I add a margin/padding to each item in the rating bar?

现在,我想知道如何为评级栏中的每个项目添加保证金/填充?

styles.xml

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

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

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"/>

Can anyone help ?

有人可以帮忙吗?

2 个解决方案

#1


3  

Using any photoshop or any editor simply You could add some empty space to the left and right sides of your PNGs.

简单地使用任何photoshop或任何编辑器您可以在PNG的左侧和右侧添加一些空白区域。

#2


2  

If you are using Drawable for the stars. Make sure your drawable have some left padding according to your requirement.

如果您使用Drawable作为星星。确保您的drawable根据您的要求有一些左边填充。

Otherwise through code its not working. Some days back I stuck with the same problem. I gone through by using the left padded image. Hope it will work.

否则通过代码不起作用。几天前我遇到了同样的问题。我通过使用左填充图像完成了。希望它会奏效。

#1


3  

Using any photoshop or any editor simply You could add some empty space to the left and right sides of your PNGs.

简单地使用任何photoshop或任何编辑器您可以在PNG的左侧和右侧添加一些空白区域。

#2


2  

If you are using Drawable for the stars. Make sure your drawable have some left padding according to your requirement.

如果您使用Drawable作为星星。确保您的drawable根据您的要求有一些左边填充。

Otherwise through code its not working. Some days back I stuck with the same problem. I gone through by using the left padded image. Hope it will work.

否则通过代码不起作用。几天前我遇到了同样的问题。我通过使用左填充图像完成了。希望它会奏效。