【问题标题】:Android rating bar set star dimensionAndroid评分栏设置星级维度
【发布时间】:2015-10-08 13:08:22
【问题描述】:

我在我的应用程序中显示评级栏,我想减小星的尺寸。 所以这里是评分栏的xml

       <RatingBar
                android:id="@+id/ratingBar"
                style="?android:attr/ratingBarStyleSmall"
                android:layout_marginLeft="20dp"
                android:layout_marginRight="20dp"
                android:layout_marginTop="10dp"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:clickable="false"
                android:max="5"
                android:stepSize="0.25"
                android:numStars="0"
                android:focusable="false"
                android:layout_gravity="center_horizontal"
                android:focusableInTouchMode="false"
                android:isIndicator="true"/>

我正在像这样设置颜色和评级

 private RatingBar ratingBar;
 Drawable ratingBarColor = ratingBar.getProgressDrawable();
ratingBar = (RatingBar) view.findViewById(R.id.ratingBar);
 Drawable ratingBarColor = ratingBar.getProgressDrawable();
ratingBar.setRating((float) (value));
 DrawableCompat.setTint(ratingBarColor, ContextCompat.getColor(getActivity(), R.color.red));

但问题是无论任何值,颜色和小数填充都不起作用。我正在使用样式来减少星尺寸。奇怪的是,如果我在 xml 中删除 style 属性,它将设置为精确值为星,但尺寸将重置为默认值。如果我将最小/最大高度添加到星形,图像将被裁剪。 这是同样的问题:-How to set the custom size of the stars in RatingBar 试过:style="?android:attr/ratingBarStyleIndicator" 仍然是同样的问题。 我不明白 style 属性有什么问题。

【问题讨论】:

  • 缩小星图尺寸
  • 颜色未根据值填充。如果我减小图像被裁剪的尺寸。请参阅链接的问题。
  • maxsize 和 minsize 等于星图大小而不是图像不裁剪
  • 那么图像尺寸在哪里减小?

标签: android ratingbar


【解决方案1】:

我不知道它是否还有用,但我创建了一个自定义库,允许您以编程方式更改星尺寸(以及其他内容):SimpleRatingBar

它的特点:

  • 完全正常工作android:layout_width:可以设置为wrap_contentmatch_parent 或abritary dp。
  • 任意数量的星星。
  • 任意步长。
  • 星星的大小可以精确控制或通过设置最大大小来控制。
  • 正常状态下的可自定义颜色(星星的边框、填充和背景以及评分栏)。
  • 按下状态下的可自定义颜色(星星的边框、填充和背景以及评分栏)。
  • 可自定义的星号间距。
  • 可自定义的星星边框宽度。
  • 可自定义的星星角半径。
  • 允许设置 OnRatingBarChangeListener
  • 星形填充可以设置为从左到右或从右到左开始(支持 RTL 语言)。
  • AnimationBuilder 集成在视图中,可通过动画以编程方式设置评分。

Here is a preview of it.

在你的情况下,你只需要这样做:

ratingbar.setStarSize(20, Dimension.DP);

或者,例如,以像素为单位:

ratingbar.setStarSize(100, Dimension.PX);

您可以在jcenterMaven Central 中找到它。因此,在您的 build.gradle 文件中,只需添加到您的依赖项:

compile 'com.iarcuschin:simpleratingbar:0.1.+'

【讨论】:

  • 感谢分享。让我试试看。
猜你喜欢
  • 2016-02-17
  • 2013-08-03
  • 2013-07-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-02-06
  • 1970-01-01
相关资源
最近更新 更多