How to make a smaller RatingBar?

前端 未结 18 1423
情话喂你
情话喂你 2020-11-27 09:29

I\'ve added a RatingBar in a layout:



        
相关标签:
18条回答
  • 2020-11-27 09:50

    After a lot of research I found the best solution to reduce the size of custom rating bars is to get the size of progress drawable in certain sizes as mentioned below :

    xxhdpi - 48*48 px

    xhdpi - 36*36 px

    hdpi - 24*24 px

    And in style put the minheight and maxheight as 16 dp for all Resolution.

    Let me know if this doesn't help you to get a best small size rating bars as these sizes I found very compatible and equivalent to ratingbar.small style attribute.

    0 讨论(0)
  • 2020-11-27 09:55

    How to glue the code given here ...

    Step-1. You need your own rating stars in res/drawable ...

    A full star

    Empty star

    Step-2 In res/drawable you need ratingstars.xml as follow ...

    <?xml version="1.0" encoding="utf-8"?>
    <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
        <item android:id="@android:id/background"
              android:drawable="@drawable/star_empty" />
        <item android:id="@android:id/secondaryProgress"
              android:drawable="@drawable/star_empty" />
        <item android:id="@android:id/progress"
              android:drawable="@drawable/star" />
    </layer-list>
    

    Step-3 In res/values you need styles.xml as follow ...

    <?xml version="1.0" encoding="utf-8"?>
    <resources>
        <style name="foodRatingBar" parent="@android:style/Widget.RatingBar">
            <item name="android:progressDrawable">@drawable/ratingstars</item>
            <item name="android:minHeight">22dip</item>
            <item name="android:maxHeight">22dip</item>
        </style>
    </resources>
    

    Step-4 In your layout ...

    <RatingBar 
          android:id="@+id/rtbProductRating"
          android:layout_height="wrap_content"
          android:layout_width="wrap_content"
          android:numStars="5"
          android:rating="3.5"
          android:isIndicator="false"
          style="@style/foodRatingBar"    
    />  
    
    0 讨论(0)
  • 2020-11-27 09:56

    I solve this issue the following: style="?android:attr/ratingBarStyleSmall"

    0 讨论(0)
  • 2020-11-27 09:59

    There is no need to add a listener to the ?android:attr/ratingBarStyleSmall. Just add android:isIndicator=false and it will capture click events, e.g.

    <RatingBar
      android:id="@+id/myRatingBar"
      style="?android:attr/ratingBarStyleSmall"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:numStars="5"
      android:isIndicator="false" />
    
    0 讨论(0)
  • 2020-11-27 10:01
     <RatingBar
                        android:rating="3.5"
                        android:stepSize="0.5"
                        android:numStars="5"
                        style = "?android:attr/ratingBarStyleSmall"
                        android:theme="@style/RatingBar"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"/>
    
    // if you want to style 
    
     <style name="RatingBar" parent="Theme.AppCompat">
            <item name="colorControlNormal">@color/colorPrimary</item>
            <item name="colorControlActivated">@color/colorAccent</item>
        </style>
    

    // add these line for small rating bar

    style = "?android:attr/ratingBarStyleSmall"
    
    0 讨论(0)
  • 2020-11-27 10:02
    <RatingBar
        android:id="@+id/ratingBar1"
        android:numStars="5"
        android:stepSize=".5"
        android:rating="3.5"
        style="@android:style/Widget.DeviceDefault.RatingBar.Small"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />
    
    0 讨论(0)
提交回复
热议问题