0

Below is my rating bar which I need to reduce its size. Please help me!

<RatingBar
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/ratingBar"
    android:numStars="3"
    android:stepSize="0.1"
    android:isIndicator="true"
    android:layout_below="@+id/textView15"
    android:layout_alignLeft="@+id/textView15"
    android:layout_alignStart="@+id/textView15"
    android:layout_alignBottom="@+id/imageView"
    android:layout_alignRight="@+id/textView15"
    android:layout_alignEnd="@+id/textView15" />
Marko
  • 20,385
  • 13
  • 48
  • 64
jobin
  • 1,489
  • 5
  • 27
  • 52

5 Answers5

5

You can apply small Ratingbar style. You can add style="?android:attr/ratingBarStyleSmall" inside and check the result.

Still if you won't satishfied. You need to set it's height and width using Android styles.

Here is the thread will give you some idea.

Community
  • 1
  • 1
Parth
  • 137
  • 8
3

Try applying style on Rating bar

style="?android:attr/ratingBarStyleSmall"

<RatingBar
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/ratingBar"
        android:numStars="3"
        android:stepSize="0.1"
        android:isIndicator="true"
        android:layout_below="@+id/textView15"
        android:layout_alignLeft="@+id/textView15"
        android:layout_alignStart="@+id/textView15"
        android:layout_alignBottom="@+id/imageView"
        android:layout_alignRight="@+id/textView15"
        android:layout_alignEnd="@+id/textView15"
        style="?android:attr/ratingBarStyleSmall"
       />

You have multiple choices here in style another one is:-

style="?android:attr/ratingBarStyle"

and this

 style="?android:attr/ratingBarStyleIndicator"
Shishram
  • 1,514
  • 11
  • 20
2

You can change this way, it works

<RatingBar
android:id="@+id/ratingBar"
style="?android:attr/ratingBarStyleSmall"
... />
2

Scale it down and add a negative bottom margin as the rating bar will stil take up its full size space.

                            <RatingBar
                                android:id="@+id/ratingBar"
                                android:layout_width="wrap_content"
                                android:layout_height="50dp"
                                android:layout_marginBottom="-26dp"
                                android:numStars="5"
                                android:stepSize="0.1"
                                android:theme="@style/RatingBar"
                                android:rating="3.5"
                                android:scaleX=".5"
                                android:scaleY=".5"
                                android:transformPivotX="0dp"
                                android:transformPivotY="0dp"
                                android:isIndicator="true" />
Rikard Askelöf
  • 2,762
  • 4
  • 20
  • 24
-5

To reduce or increase the size of any view

Instead of this :

android:layout_width="wrap_content"

android:layout_height="wrap_content"

Do this :

android:layout_width="100dp"

android:layout_height="40dp"

set width & height according to your required need

Addition:

wrap_content will always just wrap your view & will not increase or decrease the size of the view

To use on different size devices:

put the values in res->values->dimens folder for normal, small & large devices

and use like :

android:layout_width="@dimens/widthSize"

android:layout_height="@dimens/heightSize"
  • I believe the OP is intending for the stars to scale to the height of the component, but the default functionality for RatingBar is to crop them. Setting the size as you have suggested will not fix the problem. – Samah Sep 11 '16 at 23:19