无法更改自定义 RatingBar 的大小

Can't change the size of custom RatingBar

我正在尝试为我的 android 应用制作自定义 RatingBar,我可以在其中更改 RatingBar 的默认大小和颜色。为此,我为 CustomRatingBar 编写了这样的样式:

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

但是大小没有改变,而是像这样缩小了评级栏:

可绘制文件为:custom_ratingbar.xml, custom_ratingbar_empty, custom_ratingbar_filled

在我的 xml 中,RatingBar 如下所示:

         <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" />

如何在不缩小评分栏的情况下更改星级大小?

试试这个,

使用 android 的 ratingBar small 样式自定义评分栏样式。

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

检查 example. 是否相同。

其他解决方案是:

Android 不会缩放评级栏图标。当您减小 minHeight 和 maxHeight android 时,将始终裁剪图标,如图所示。似乎唯一的解决方案是为具有所需尺寸的星星提供您自己的图标,并将 minHeight 和 maxHeight 设置为图标的大小。

我遇到了同样的问题,尽管这个问题很老了,但我希望这对遇到这种情况的人有所帮助。

要增加评分栏中星星的大小,我们需要使用 android:scaleX 和 android:scaleY。

请参考以下例子:

<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"/>

此外,您可以在 https://en.proft.me/2017/06/18/decorating-ratingbar-android/

找到更多详细信息

只需在 xml 布局

中将以下行添加到您的评分栏
    android:scaleX="0.5"
    android:scaleY="0.5"
<..
 android:scaleX=".6"
 android:scaleY=".6"
 //to avoid the unnecessary space
 android:transformPivotX="0dp"
 ../>