简体   繁体   中英

How can I set the float type x.5 in Rating Bar?

I have a problem. the problem is that I can't see half rating of rating bar. For example,there is ratingbar set numStar="5",stepSize="0.5",isIndicator="true". and then I used RatingBar method:setRating and set rating=2.5. I thought this RatingBar will show me 2start+a half star. but this rating bar expressed 3 start. I can't figure it out.. somebody help me..

example code :

RatingBar rt =(RatingBar)findViewById(R.id.ratingbar1);
rt.setNumStart=5;
rt.setStepSize=0.5f;
rt.setRating(2.5f);
RatingBar rt =(RatingBar)findViewById(R.id.ratingBar);
rt.setIsIndicator(true);
rt.setNumStars(5);
rt.setStepSize(0.5f);
rt.setRating(2.5f);

I used the same code and it is working for me. It is probably a bug, or maybe there is a problem while trying to set the rating. If you are setting the value from a variable, then try rt.setRating((float) var) See Screenshot

UPDATE: Setting max value seems to solve the problem for some users, try rt.setMax(5)

float aveRating=totalSum/totalIndex;

        float refRat= (float) (aveRating-(Math.floor(aveRating)));
        float setRat=0;

        if(refRat>=0.7){
            setRat=Math.round(aveRating);
            Toast.makeText(this,"0.7이상:"+ setRat,Toast.LENGTH_SHORT).show();
        }
        else if(refRat<0.7 && refRat>=0.3){
            setRat= (float) (Math.floor(aveRating)+(float)0.5);
            Toast.makeText(this,"0.7이하 0.5이상 :" + setRat,Toast.LENGTH_SHORT).show();
        }
        else if(refRat<0.3){
            setRat= (float) Math.floor(aveRating);
            Toast.makeText(this," 0.5이하:"+ setRat,Toast.LENGTH_SHORT).show();
        }

        String stringAveRat = String.format("%.1f" , aveRating);

        ksRatingBar.setRating((float)setRat);
        ksRatingText.setText(stringAveRat);

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