2
 val rating = jsonObject.getInt("rating")

for instance, a rating of 4, to be displayed as 4 stars in my view.

I am looking for ways to display it programatically as image views or to use Ratingsbar

Ridcully
  • 23,362
  • 7
  • 71
  • 86
chigirl
  • 69
  • 8

1 Answers1

0

Use RatingBar, in your view:

<RatingBar
    android:id="@+id/ratingBar"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"/>

In your Activity: Use synthetic Just type the id of your RatingBar and it'll get your RatingBar

import kotlinx.android.synthetic.main.your_activity.*

val rating = jsonObject.getInt("rating")
ratingBar.numStars = rating

or just old school:

val rBar: RatingBar = findViewById(R.id.ratingBar)
rBar.numStars = rating

Edit: As you wanted to know about resizing:

<RatingBar
        android:id="@+id/ratingBar"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:max="5"
        android:rating="3.5"
        android:scaleX=".5"
        android:scaleY=".5"
        android:transformPivotX="0dp"
        android:transformPivotY="0dp" />

You can use scaleX & scaleY to resize accordingly (chose a balanced value of both) the base value is 1 for both. (.5,.5 will make it half of the original size.)

Here's a question about resizing: How can I decrease the size of Ratingbar?

some user
  • 1,693
  • 2
  • 14
  • 31
  • Hi, do you know how I can change the size of the stars? I tried to use style="@style/Widget.AppCompat.RatingBar.Small" but it is not working – chigirl Feb 10 '20 at 20:29