Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android RatingBar numStart not working

I have simple RatingBar in my app. and i set numStarts="5" but it show more then 5 star. when i set android:layout_width="match_parent" I tried to several tutorials but also did't work, as per doc numStarts for show number of starts but in my case it did't work. i go through doc and several tutorials but did't get any solution.

enter image description here

but i want to only 5 stars in rating bar.

my rating bar is given below.

<RatingBar
    style="@style/customRatingBar"
    android:id="@+id/course_rating_bar"
    android:layout_height="match_parent"
    android:layout_width="match_parent"
    android:layout_marginRight="16dp"
    android:layout_marginLeft="16dp"
    android:numStars="5"
    android:isIndicator="false"
    android:stepSize="1.0"/>

This is my custom style

<style name="foodRatingBar" parent="@android:style/Widget.RatingBar">
        <item name="android:progressDrawable">@drawable/ratingstars</item>
        <item name="android:minHeight">22dip</item>
        <item name="android:maxHeight">22dip</item>
    </style>

......

<?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_empty" />
    <item android:id="@+android:id/secondaryProgress"
        android:drawable="@drawable/star_empty" />
    <item android:id="@+android:id/progress"
        android:drawable="@drawable/star" />
</layer-list>
like image 615
Mansukh Ahir Avatar asked Jan 08 '23 16:01

Mansukh Ahir


1 Answers

You have to set android:layout_width="wrap_content" rather than "match_parent". Then you will get the 5 stars.

like image 136
akhil nair Avatar answered Jan 10 '23 07:01

akhil nair