如何使的RatingBar显示五颗星五颗星、RatingBar

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

我下面的如何添加的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)
 

Android中RatingBar的自定义效果

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)

阅读全文

相关推荐

最新文章