Java – Add margins/padding to the RatingBar

Add margins/padding to the RatingBar… here is a solution to the problem.

Add margins/padding to the RatingBar

I have a picture of a rating bar like this:

enter image description here

Now, I want to know how to add margins/padding to each item in the grading bar?

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

Can someone help?

Solution

Use any Photoshop or any editor
Simply put, you can add some white space to the left and right of the PNG.

Related Problems and Solutions