简体   繁体   English

Android评分栏中的StepSize

[英]StepSize in Rating Bar Android

   <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"
    />

If I give rating from 3.1 to 3.5,then rating showing is 3.5 only. 如果我的评分从3.1到3.5,则显示的评分仅为3.5。

I need rating to be set in exact value(eg: 3.1). 我需要将评级设置为精确值(例如:3.1)。

StepSize is also set to 0.1. StepSize也设置为0.1。

Please anyone help me in this. 请任何人在这方面帮助我。

Thanks in Advance. 提前致谢。

TRY LIKE THIS 尝试这个

  <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();
            }

        }
    });

Try this: 尝试这个:

<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"
           />

If you set secondaryProgressTint in RatingBar , it will work with versions >= 21 . 如果您在RatingBar设置secondaryProgressTint ,则它将与版本> = 21一起使用 To support all versions use AppCompatRatingBar 要支持所有版本,请使用AppCompatRatingBar

Try to adjust your ratingBar with the property android:width="match_parent" in your parent layout, this will take your step size in mind and behave with decimal rating. 尝试在父级布局中使用属性android:width =“ match_parent”调整您的ratingBar,这会考虑您的步长并采用十进制评级。

you can better get it Here . 你最好在这里得到它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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