StepSize在评级栏Android

时间:2017-09-06 05:31:38

标签: android ratingbar

   <RatingBar
    android:id="@+id/ratingBar"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:numStars="5"
    android:stepSize="0.1"
    android:isIndicator="true"
    android:rating="3.1"
    />

如果我给出评分从3.1到3.5,则评分显示仅为3.5。

我需要将评级设置为精确值(例如:3.1)。

StepSize也设置为0.1。

请有人帮助我。

先谢谢。

3 个答案:

答案 0 :(得分:0)

  

试试这个

  <RatingBar
    android:id="@+id/ratingBar"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:numStars="5"
    android:stepSize="1"
    />


    ratingBar.setOnRatingBarChangeListener(new RatingBar.OnRatingBarChangeListener() {
        @Override
        public void onRatingChanged(RatingBar ratingBar, float rating, boolean fromUser) {

            if(rating == 1.0)
            {
                Toast.makeText(MainActivity.this, "3.1", Toast.LENGTH_SHORT).show();
            }
            else if(rating == 2.0)
            {
                Toast.makeText(MainActivity.this, "3.2", Toast.LENGTH_SHORT).show();
            }

        }
    });

答案 1 :(得分:0)

试试这个:

<android.support.v7.widget.AppCompatRatingBar
            android:id="@+id/rb"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_margin="10dp"
            android:isIndicator="false"
            android:numStars="6"
            android:stepSize=".1"
            app:secondaryProgressTint="#00000000"
            android:numStars="6"
           />

如果您在secondaryProgressTint中设置RatingBar,则可以使用版本&gt; = 21 。要支持所有版本,请使用AppCompatRatingBar

答案 2 :(得分:-1)

尝试使用属性android:width =“match_parent”调整您的ratingBar  在您的父布局中,这将考虑您的步长并使用小数等级。

你可以更好地获得它Here