2017-07-31 87 views
0

我已經爲我的代碼添加了RatingBar,除了一件事情之外,它運行良好。我試圖將步長設置爲0.1,但它仍然按照默認的0.5步長進行反應。我可以很容易地設置一個高於0.5的步長,它會按預期做出反應,但不會降低。我想不出爲什麼?唯一我能想到的是RatingBar的步長限制在0.5?對於評分欄來說,最低限度的拉半星是沒有意義的?Android:Ratingbar步長小於0.5

<android.support.v7.widget.AppCompatRatingBar 
    android:theme="@style/RatingBar" 
    android:stepSize="0.1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:id="@+id/ratingbar" 
    android:numStars="5" 
    android:rating="0.1" 
    style="?android:attr/ratingBarStyleSmall" 
    android:layout_below="@+id/title" 
    android:layout_centerHorizontal="true" /> 

上面的代碼會顯示一半的明星。但據我所知,它應該畫一顆星的十分之一。

P.S我試圖以編程方式實現它,但仍然一樣。

回答

0

我通過設置secondaryProgressTint爲透明的#00000000來解決這個問題。

secondaryProgressTint填充剩餘的已開始恆星。默認顏色顯然設置爲與主要progressTint相同的顏色,因此如果您不知道,會導致很多混淆。

<android.support.v7.widget.AppCompatRatingBar 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:id="@+id/ratingbar" 
      style="?android:attr/ratingBarStyleSmall" 
      android:isIndicator="true" 
      android:progressTint="@color/Red" 
      android:secondaryProgressTint="#00000000" 
      android:numStars="5" 
      android:rating="3.3" 
      android:stepSize="0.1" 
      android:layout_below="@+id/title" 
      android:layout_centerHorizontal="true" 
      />