【问题标题】:Can't change the size of custom RatingBar无法更改自定义 RatingBar 的大小
【发布时间】:2016-05-15 07:09:04
【问题描述】:

我正在尝试为我的 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.xmlcustom_ratingbar_emptycustom_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" />

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

【问题讨论】:

  • 使用:style="?android:attr/ratingBarStyleSmall"
  • 您使用的图标大小是多少?使用更大的图标,如 48x48 或 50x50 并保存在 xxhdpi 文件夹中。

标签: android xml android-layout android-studio ratingbar


【解决方案1】:

只需在 xml 布局中的 ratingBar 中添加以下行

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

【讨论】:

    【解决方案2】:

    试试这个,

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

    <?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 设置为图标的大小。

    【讨论】:

    • 它在底部留出了一些空间,但星星的大小没有改变。
    • 我已按照示例教程制作自定义 ratingBar。
    • 我已经尝试过这个例子并且它有效,所以我提供了那个链接@pialkanti
    【解决方案3】:

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

    要增加评分栏中星星的大小,我们需要使用 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/找到更多详细信息

    【讨论】:

      【解决方案4】:
      <..
       android:scaleX=".6"
       android:scaleY=".6"
       //to avoid the unnecessary space
       android:transformPivotX="0dp"
       ../>
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2015-12-30
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-05-26
        • 2012-09-05
        • 1970-01-01
        相关资源
        最近更新 更多