如何使的RatingBar显示五颗星 [英] How to make RatingBar to show five stars

查看:717
本文介绍了如何使的RatingBar显示五颗星的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我下面的如何添加的RatingBar 标准的例子。为了控制我试图用星的数量安卓numStars =5。问题是,似乎星星的数量根本不进行任何操作。在纵向布局我得到6分,当我翻转手机,我得到10分。我试图设置数星星在我的活动( myBar.setNumStars(5))的加载XML,但没有与该选项没有成功要么。

所以我的问题是如何定义我的布局,使其只显示五颗星?设置 numStars 似乎并没有工作。

在此先感谢, 罗兰

解决方案

 <的RatingBar
            机器人:ID =@ + ID /等级
            机器人:layout_width =WRAP_CONTENT
            机器人:layout_height =WRAP_CONTENT
            风格=机器人:ATTR / ratingBarStyleSmall
            机器人:numStars =5
            机器人:stepSize的=0.1
            机器人:isIndicator =真/>
 

在code

  mRatingBar.setRating(INT)
 

I am following the standard example of how to add a RatingBar. To control the number of stars I tried to use android:numStars="5". The problem is that the number of stars doesn't seem to do anything at all. In portrait-layout I get 6 stars and when I flip the phone I get about 10 stars. I tried to set the number of stars in my Activity (myBar.setNumStars(5)) that loads the xml but there was no success with that option either.

So my question is how do I define my layout so that it will only show five stars? Set numStars doesn't seem to work.

Thanks in advance, Roland

解决方案

<RatingBar
            android:id="@+id/rating"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            style="?android:attr/ratingBarStyleSmall"
            android:numStars="5"
            android:stepSize="0.1"
            android:isIndicator="true" />

in code

mRatingBar.setRating(int)

这篇关于如何使的RatingBar显示五颗星的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆