[英]Android rating bar set star dimension
I am displaying rating bar in my application where i want to reduce the dimensions of the star. 我在我想缩小星星尺寸的应用程序中显示评分栏。 so here is xml of rating bar
所以这是评级栏的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"/>
i am setting color and setting rating like this 我正在这样设置颜色和设置等级
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));
But the problem is regardless of any value the color and decimal filling won't work.I am using style to reduce star dimensions.strange is if i remove style attribute in xml it will set exact value as star but dimension will reset to default.if i add min/max height to star the image will get cropped. 但是问题是无论任何值,颜色和十进制填充都不起作用。我正在使用样式来减小星形尺寸。奇怪的是,如果我在xml中删除样式属性,它将设置准确的值作为星形,但是尺寸将重置为默认值。如果我将最小/最大高度加到星形,图像将被裁剪。 here is the same problem :- How to set the custom size of the stars in RatingBar tried :
style="?android:attr/ratingBarStyleIndicator"
still same issue. 这是相同的问题:- 如何在RatingBar中设置星星的自定义大小,尝试过:
style="?android:attr/ratingBarStyleIndicator"
仍然是同一问题。 i am not getting what's wrong with the style attribute. 我没有得到样式属性有什么问题。
I don't know if it will be useful anymore, but I made a custom library which allows you to change star dimension programatically (among other stuff): SimpleRatingBar . 我不知道它是否会有用,但我创建了一个自定义库,该库可让您以编程方式(以及其他方法)更改星形尺寸: SimpleRatingBar 。
It features: 它具有以下特点:
android:layout_width
: it can be set to wrap_content
, match_parent
or abritary dp. android:layout_width
:可以将其设置为wrap_content
, match_parent
或非婚生dp。 Here is a preview of it . 这是它的预览 。
In your case, you would just have to do: 就您而言,您只需要执行以下操作:
ratingbar.setStarSize(20, Dimension.DP);
or, for example, in pixels: 或以像素为单位:
ratingbar.setStarSize(100, Dimension.PX);
You can find it either in jcenter
or in Maven Central
. 您可以在
jcenter
或Maven Central
找到它。 So in your build.gradle
file just add to your dependencies: 因此,在您的
build.gradle
文件中,只需添加您的依赖项即可:
compile 'com.iarcuschin:simpleratingbar:0.1.+'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.