在我的活动中,我有一些评级酒吧。但是这个酒吧的大小非常大! 如何让它更小?如何缩小评分栏的大小?
编辑
由于加布里埃尔Negut, 我用下面的风格做到了:现在
<RatingBar
style = "?android:attr/ratingBarStyleSmall"
android:numStars = "5"
android:rating = "4" />
,尺寸减小,但明星和分级数不生效! ! 为什么?我有7颗星,其中6个被选中。
在我的活动中,我有一些评级酒吧。但是这个酒吧的大小非常大! 如何让它更小?如何缩小评分栏的大小?
编辑
由于加布里埃尔Negut, 我用下面的风格做到了:现在
<RatingBar
style = "?android:attr/ratingBarStyleSmall"
android:numStars = "5"
android:rating = "4" />
,尺寸减小,但明星和分级数不生效! ! 为什么?我有7颗星,其中6个被选中。
我发布的原始链接现在已被破坏(有一个很好的理由说明为什么发布链接不是最好的方法)。您必须使用ratingBarStyleSmall
或从Widget.Material.RatingBar.Small
继承的自定义样式(假设您在应用中使用Material Design)来设计RatingBar
。
选项1:
<RatingBar
android:id="@+id/ratingBar"
style="?android:attr/ratingBarStyleSmall"
... />
选项2:
// styles.xml
<style name="customRatingBar"
parent="android:style/Widget.Material.RatingBar.Small">
... // Additional customizations
</style>
// layout.xml
<RatingBar
android:id="@+id/ratingBar"
style="@style/customRatingBar"
... />
或使用此样式style =“?android:attr/ratingBarStyleSmall”将减小大小。 – 2014-12-10 05:46:08
给定的链接已损坏。 – darwin 2016-04-23 07:05:51
链接被破坏,所以SO社区不鼓励只有链接的答案。 – 2016-08-17 06:13:38
如果你只需要默认的样式,请确保您有以下宽度/高度,否则numStars可以搞的一团糟:
android:layout_width="wrap_content"
android:layout_height="wrap_content"
使用此样式style =“?android:attr/ratingBarStyleSmall”将缩小尺寸 – 2014-12-10 05:44:49
您可以在RatingBar
的XML代码中设置它,使用scaleX
和scaleY
进行相应调整。 “1.0”将是正常大小,“.0”中的任何内容都会减少它,而大于“1.0”的任何内容都会增加它。
<RatingBar
android:id="@+id/ratingBar1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleX="0.5"
android:scaleY="0.5" />
与此相关的问题是,即使图标较小,评级栏仍会占用与之前相同的宽度和高度。这会导致对齐问题,因为第一个和最后一个图标旁边有一堆左右填充。例如,如果您希望像这样的“XXXXX”图标,缩放后它将看起来像这样“----- XXXXX -----”,其中“ - ”是空的空间,“X”是一个图标。所以你的评级栏似乎是因为空的空间而被推到右边 – theDazzler 2014-04-05 23:15:45
我猜你正在使用相对布局。这是一个痛苦,但你可以通过使用'android:layout_marginRight'和喜欢的方式来调整它到正确的位置。 – ZeWolfe15 2014-04-30 01:20:15
至少它适用于我,谢谢 – frostymarvelous 2014-06-16 15:01:32
如果您想要以小尺寸显示评级栏,只需将此代码复制并粘贴到您的项目中。
<RatingBar
android:id="@+id/MyRating"
style="?android:attr/ratingBarStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/getRating"
android:isIndicator="true"
android:numStars="5"
android:stepSize="0.1" />
什么是android:stepSize =“0.1”? – darwin 2016-04-23 07:25:04
http://codingaffairs.blogspot.com/2016/05/android-material-design-small-rating-bar.html – 2016-05-18 17:05:47
也检查我的asnwer在这个页面的末尾。 – 2016-05-18 17:06:02
这是经过大量的努力,以减少小型评级酒吧,甚至没有丑陋的填充
<RatingBar
android:id="@+id/listitemrating"
style="@android:attr/ratingBarStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleX=".5"
android:scaleY=".5"
android:transformPivotX="0dp"
android:transformPivotY="0dp"
android:isIndicator="true"
android:max="5" />
在的RatingBar给属性 风格=我的解决方案“机器人:ATTR/ratingBarStyleIndicator”
<RatingBar
style="?android:attr/ratingBarStyleIndicator"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
你能详细说明你是如何到达解决方案的吗? – onebree 2015-08-18 12:38:17
<RatingBar
style="@style/RatingBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:numStars="5"
android:rating="3.5"
android:stepSize="0.5" />
,并在您的样式xml文件
<style name="RatingBar"
parent="android:style/Widget.Material.RatingBar.Small">
<item name="colorControlNormal">@color/primary_light</item>
<item name="colorControlActivated">@color/primary_dark</item>
</style>
这样,你不需要定制的RatingBar添加此。
以下代码段为我工作来调整的RatingBar
<RatingBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/ratingBar"
style="?android:attr/ratingBarStyleIndicator"
android:scaleX=".5"
android:rating="3.5"
android:scaleY=".5"
android:transformPivotX="0dp"
android:transformPivotY="0dp"
android:max="5"/>
如何更改此评分栏半填充,满填充以及空白色的暂停栏颜色? – 2016-12-06 07:43:47
评分参数用于填写评分栏吧?我使用了android:rating =“3.5”,因此3.5星满了。你可以设置为5,因为max = 5被设置在xml中。 如果要更改评级栏的颜色,则必须在style.xml中创建样式,请参阅以下链接:http://stackoverflow.com/a/35914622/2915785 – 2016-12-06 13:22:28
如何使用android:transformPivotX =“0dp” android:transformPivotY =“0dp”以编程方式? – 2016-12-16 04:36:52
你的意思是搜索条?设置高度和宽度对我来说很好。你能在这里发布你的代码片段吗? – 2011-05-27 14:28:55
我会建议删除“编辑”,而不是使其成为公认的答案。那或者@GabrielNegut可以编辑他的答案来包含这种解决方案。将问题中的解决方案包括在内,可以消除问答体验。 – onebree 2015-08-18 12:37:37
'style =“?android:attr/ratingBarStyleSmall”'适合我。 – 2016-01-18 18:59:32