Reputation: 61
My requirement is to open a dialog that allows users to rate content and it has 10 stars in the dialog. I tried different things but it didn't work. Below is my rating_dialog.xml
file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="300dp"
android:layout_height="match_parent"
android:background="@color/colorWhite"
android:orientation="vertical">
<RatingBar
android:id="@+id/dialog_rating_bar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="?android:attr/ratingBarStyleSmall"
android:layout_marginTop="@dimen/margin_15"
android:layout_gravity="center"
android:layout_marginEnd="@dimen/margin_30"
android:progressBackgroundTint="@color/colorHint"
android:progressTint="@color/color_orange"
android:secondaryProgressTint="@color/color_orange"
android:numStars="10"
android:scaleX="1.8"
android:scaleY="1.8" />
</LinearLayout>
It shows only 9 stars and the Rating Bar layout is also not proper. Any help is appreciated. Thanks!!!
Upvotes: 0
Views: 1233
Reputation: 402
You can try like this. Working for me opened with bottom
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="62dp"
android:gravity="center_horizontal"
android:padding="@dimen/_10sdp"
android:text="@string/str_rate_this"
android:textSize="@dimen/_15sdp" />
<RatingBar
style="@style/Widget.AppCompat.RatingBar.Indicator"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:numStars="10"
android:rating="5"
android:layout_gravity="center_horizontal"
android:isIndicator="false"
android:scaleX=".9"
android:scaleY=".9"
android:stepSize="1" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:background="@drawable/rectangle_background"
android:layout_margin="@dimen/_20sdp"
android:text="Rate now" />
</LinearLayout>
Upvotes: 4
Reputation: 854
I once used this library,you can choose the amount of stars you want
Upvotes: 0
Reputation: 3928
You have given android:layout_width="300dp"
to your root LinearLayout
and that is a reason why it is not showing 10th star.
To make it work you need to give it match_parent
or wrap_content
based on your requirement
Upvotes: 1
Reputation: 969
<RatingBar
android:id="@+id/dialog_rating_bar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="?android:attr/ratingBarStyleSmall"
android:layout_marginTop="@dimen/margin_15"
android:layout_gravity="center"
android:layout_marginEnd="@dimen/margin_30"
android:layout_marginStart="@dimen/margin_30"
android:progressBackgroundTint="@color/colorHint"
android:progressTint="@color/color_orange"
android:secondaryProgressTint="@color/color_orange"
android:numStars="10"
android:scaleX="1.8"
android:scaleY="1.2" />
Just to fit the star I have reduced the scaleY to 1.2.
Upvotes: 0