简体   繁体   中英

ratingbar cannot show only full stars

I'm trying to show only full stars in rating bar with 10. but when I click to rate, not showing full star

<RatingBar
    android:id="@+id/ratingBar"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:numStars="10"
    android:stepSize="1.0"
    android:max="10"
    android:layout_weight="1" />

输出屏幕截图

What's messing it up is the width of the view. I messed around a bit with it and it seems that 10 stars is too broad to fit them all on the screen. This messes up the view. If you try to put it in landscape mode, you'll notice that it will work. You'll either have to do this in landscape or have less or smaller stars, so that they fit within the screen's width.

Try this .

You RatingBar star is more bigger in default.

Use style="@style/Widget.AppCompat.RatingBar.Small" in RatingBar

Remove android:layout_weight="1"

<RatingBar
    android:id="@+id/ratingBar"
    style="@style/Widget.AppCompat.RatingBar.Small"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:numStars="10"
    android:rating="2.5"
    android:stepSize=".5"/>

Stars in a RatingBar are not resized by Android.Use custom style in rating bar to resize the rating bar.

<style name="MyRatingBar" parent="@android:style/Widget.DeviceDefault.RatingBar.Indicator">
    <item name="android:minHeight">48dp</item>
    <item name="android:maxHeight">48dp</item>
</style>

And then add that style to rating bar

<RatingBar
    android:id="@+id/ratingBar"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:numStars="10"
    android:stepSize="1.0"
    android:max="10"
    style="@style/MyRatingBar"  />

For more info on the issue check here http://web.archive.org/web/20160323223259/http://kozyr.zydako.net/2010/05/23/pretty-ratingbar/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM