如何减小评级栏的大小?
在我的活动中,我有一些评级栏。但是这个酒吧的面积实在是太大了! 我怎样才能让它变小?
编辑
感谢 Gabriel Negut, 我用以下样式做到了:
<RatingBar
style = "?android:attr/ratingBarStyleSmall"
android:numStars = "5"
android:rating = "4" />
现在,大小缩小了,但星星数量和评级不生效! 为什么?我有 7 颗星,其中 6 颗被选中。
In my activity I have some Rating bars. But the size of this bar is so big!
How can I make it smaller?
Edit
Thanks to Gabriel Negut,
I did it with the following style:
<RatingBar
style = "?android:attr/ratingBarStyleSmall"
android:numStars = "5"
android:rating = "4" />
Now, the size is reduced but number of stars and rating do not take effect!!!
Why? I have 7 stars that 6 of them is selected.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(18)
使用
Widget.AppCompat.RatingBar
,您有 2 种样式可供使用;Indicator
和Small
分别表示大尺寸和小尺寸。请参阅下面的示例。Using
Widget.AppCompat.RatingBar
, you have 2 styles to use;Indicator
andSmall
for large and small sizes respectively. See example below.在
RatingBar
中给出属性:In
RatingBar
give attribute:如果您在 Linearlayout 中使用带有 WeightSum 的评级栏。请确保您不应该为评级栏分配layout_weight。相反,它将评级栏放置在相对布局内,并赋予相对布局权重。使评级栏宽度包裹内容。
If you are using Rating bar in Linearlayout with weightSum. Please make sure that you should not assign the layout_weight for rating bar. Instead, that place rating bar inside relative layout and give weight to the relative layout. Make rating bar width wrap content.
只需使用
style="@style/Widget.AppCompat.RatingBar.Small"
就可以了!Just use
style="@style/Widget.AppCompat.RatingBar.Small"
it'll work for Sure!如果您只需要默认样式,请确保具有以下宽度/高度,否则 numStars 可能会变得混乱:
If you only need the default style, make sure you have the following width/height, otherwise the numStars could get messed up:
对于那些以编程方式创建评级栏并希望设置小评级栏而不是默认的大评级栏的人
For those who created rating bar programmatically and want set small rating bar instead of default big rating bar
我发布的原始链接现已损坏(有充分的理由说明为什么仅发布链接不是最好的方法)。您必须使用
RatingBarStyleSmall
或继承自Widget.Material.RatingBar.Small
的自定义样式来设置RatingBar
的样式(假设您使用的是 Material在您的应用程序中进行设计)。选项 1:
选项 2:
The original link I posted is now broken (there's a good reason why posting links only is not the best way to go). You have to style the
RatingBar
with eitherratingBarStyleSmall
or a custom style inheriting fromWidget.Material.RatingBar.Small
(assuming you're using Material Design in your app).Option 1:
Option 2:
这是我的解决方案,经过一番努力,以小尺寸减小评级栏,甚至没有丑陋的填充
This was my solution after a lot of struggling to reduce the rating bar in small size without even ugly padding
如果您想以小尺寸显示评级栏,只需复制此代码并将其粘贴到您的项目中即可。
If you want to show the rating bar in small size, then just copy and paste this code in your project.
下面的代码片段帮助我调整了 ratingBar
The below snippet worked for me to resize the ratingBar
您可以在
RatingBar
的 XML 代码中进行设置,使用scaleX
和scaleY
进行相应调整。 “1.0”是正常大小,“.0”中的任何内容都会减少它,任何大于“1.0”的内容都会增加它。You can set it in the XML code for the
RatingBar
, usescaleX
andscaleY
to adjust accordingly. "1.0" would be the normal size, and anything in the ".0" will reduce it, also anything greater than "1.0" will increase it.工作示例
并将其添加到您的styles xml 文件
这样你就不需要自定义 ratingBar。
Working Example
and add this in your styles xml file
This way you dont need to customise ratingBar.
此处查看我的答案。实现它的最佳方式。
并使用像
Check my answer here. Best way to achieve it.
and use like
这将完美地工作
This will work perfectly
这对我有用。
This Worked for me.
在
RatingBar
标记中,添加这两行In the
RatingBar
tag, add these two lines