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
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
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?