Can't change the size of custom RatingBar

情到浓时终转凉″ 提交于 2019-12-22 18:59:06

问题


I am trying to make custom RatingBar for my android app in which i can change the default size and color of RatingBar. For this purpose i have written styles for CustomRatingBar like this:

<style name="CustomRatingBar" parent="@android:style/Widget.RatingBar">
    <item name="android:progressDrawable">@drawable/custom_ratingbar</item>
    <item name="android:minHeight">25dp</item>
    <item name="android:maxHeight">25dp</item>
</style>

But the size is not changed rather it shrinks the rating bar like this:

Drawable files are : custom_ratingbar.xml, custom_ratingbar_empty, custom_ratingbar_filled

In my xml, RatingBar looks like below:

         <RatingBar
                    android:id="@+id/RatingBar"
                    style="@style/CustomRatingBar"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="10dp"
                    android:isIndicator="true"
                    android:numStars="5" />

How can i change the star size of the rating bar without shrinking it?


回答1:


Try this ,

custom rating bar style using android’s ratingBar small style.

<?xml version="1.0" encoding="utf-8"?>
<resources>
  <style name="CustomRatingBar" parent="@android:style/Widget.RatingBar" >
 <item name="android:numStars">5</item>
 <item name="android:rating">4.5</item>
 <item name="android:stepSize">0.5</item>
 <item name="android:layout_width">wrap_content</item>
 <item name="android:layout_height">wrap_content</item>
 <item name="android:paddingBottom">44dip</item>
 <item name="android:layout_marginLeft">4dip</item>
 <item name="android:layout_marginTop">4dip</item>

Check example. for the same.

Other solution is :

Android won't scale a rating bar icons. When you decrease the minHeight and maxHeight android will always crop the icons as shown on the picture. There seems to be the only one solution is to provide your own icons for stars with the desired dimensions and set the minHeight and maxHeight to the size of the icons.




回答2:


Just add below lines to your ratingBar in xml layout

    android:scaleX="0.5"
    android:scaleY="0.5"



回答3:


I came across the same issue and even though this question is very old, I hope this will help someone who comes across this kind of scenario.

To increase the size of the stars in the rating bar we need to use android:scaleX and android:scaleY.

Please refer to the following example:

<RatingBar
android:id="@+id/ratingBar"
android:numStars="5"
android:rating="4"
android:isIndicator="true"
android:scaleX=".5"
android:scaleY=".5"
android:transformPivotX="0dp"
android:transformPivotY="0dp"
android:layout_marginBottom="-26dp"
android:layout_marginRight="-100dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:theme="@style/FoursquareReviewRating"/>

Also, you can find more details at https://en.proft.me/2017/06/18/decorating-ratingbar-android/



来源:https://stackoverflow.com/questions/35221909/cant-change-the-size-of-custom-ratingbar

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!