I am following the standard example of how to add a RatingBar
. To control the number of stars I tried to use android:numStars=\"5\"
. The problem is
If you are using
android:layout_width="match_parent"
Use wrap_content and it will only show the set numStars :)
android:layout_width="wrap_content"
The default value is set with andoid:rating in the xml layout.
The RatingBar.setNumStar
documentation says:
Sets the number of stars to show. In order for these to be shown properly, it is recommended the layout width of this widget be wrap content.
So setting the layout width to wrap_content
should solve this problem.
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<RatingBar
android:id="@+id/ruleRatingBar"
android:isIndicator="true"
android:numStars="5"
android:stepSize="0.5"
style="?android:attr/ratingBarStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</LinearLayout>
This worked for me: RatingBar
should be inside LinearLayout
other than having layout width set to wrap content for RatingBar
.
View android.view.LayoutInflater.inflate(int resource, ViewGroup root, boolean attachToRoot)
Below params are necessary for all the attributes to work properly:
root
to parent
attachToRoot
as false
Ex: convertView = inflater.inflate(R.layout.myId, parent, false);