【问题标题】:How to remove padding from Rating Bar in Android? [duplicate]如何从 Android 的评级栏中删除填充? [复制]
【发布时间】:2019-01-07 08:46:26
【问题描述】:

我的应用程序上有评分栏,它看起来像这样:

我尝试将填充设置为 0dp,但视图没有任何变化。

 <RatingBar
      android:id="@+id/ratingBar"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:numStars="5"
      android:layout_marginStart="16dp"
      android:isIndicator="false"
      style="@style/Widget.AppCompat.RatingBar"/>

预期结果:我期待评分栏没有右填充和底部填充。

【问题讨论】:

  • RatingBar.的父布局更新问题

标签: java android android-layout kotlin ratingbar


【解决方案1】:

你可以简单地调整这个

style="@android:style/Widget.DeviceDefault.RatingBar.Small"

而不是

style="@style/Widget.AppCompat.RatingBar

【讨论】:

    【解决方案2】:

    我将此添加到我的 xml 代码中,它解决了我的问题:

    android:scaleX="1"
    android:scaleY="1"
    

    【讨论】:

    • 是的,但是如果您需要像图片中那样更小的比例尺怎么办?
    【解决方案3】:

    内置的 Android 评分栏在视觉上非常有问题,在这种情况下,我宁愿使用 Android 用户所做的改进,根据对象的大小调整每个星的大小。 附上一个方便使用的库,相信这个库会为你解决很多开发中的问题。

    https://github.com/xckevin/AndroidSmartRatingBar?utm_source=android-arsenal.com&utm_medium=referral&utm_campaign=7405

    感谢开发者 kevin.liu (xckevin)。

    【讨论】:

      【解决方案4】:

      使用 scale x 和 y 来减小 start size 和 step size 来设置star size

      【讨论】:

        【解决方案5】:

        试试这个 xml 代码

        <?xml version="1.0" encoding="utf-8"?>
        <LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/main_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="center_horizontal">
        
        <RatingBar
            android:id="@+id/ratingBar"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:numStars="5"
            android:isIndicator="false"
            style="@style/Widget.AppCompat.RatingBar" />
        </LinearLayout>
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2017-03-08
          • 2015-08-22
          • 2020-08-20
          • 1970-01-01
          相关资源
          最近更新 更多