[英]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"
/>
如果我的評分從3.1到3.5,則顯示的評分僅為3.5。
我需要將評級設置為精確值(例如:3.1)。
StepSize也設置為0.1。
請任何人在這方面幫助我。
提前致謝。
嘗試這個
<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();
}
}
});
嘗試這個:
<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"
/>
如果您在RatingBar
設置secondaryProgressTint
,則它將與版本> = 21一起使用 。 要支持所有版本,請使用AppCompatRatingBar
嘗試在父級布局中使用屬性android:width =“ match_parent”調整您的ratingBar,這會考慮您的步長並采用十進制評級。
你最好在這里得到它。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.