我在每行中使用RecyclerView
和RatingBar
。現在,有時候RatingBar
的一部分被錯誤地繪製。離開一個屏幕後,回去一切都恢復正常。我不知道爲什麼會發生這種情況,我甚至從RatingBar
中刪除了任何樣式,所以它應該具有默認外觀。RatingBar變得半透明
這是它的外觀:
測試在Nexus 6P(安卓7.1.1)。 也在三星Galaxy J3(2016)(Android 5.1.1)上測試過,這裏沒有問題。
我也onBindViewHolder()
添加
holder.rbRating.requestLayout();
。它減少了一些問題,但仍然存在。當我重複使用時,將一個「壞」行滾出屏幕時,它看起來很好。
這裏的排佈局:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:paddingTop="@dimen/main_margin_top"
android:paddingBottom="@dimen/main_margin_top"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/tvRatingTitle"
android:text="Czystość wody"
android:textSize="16sp"
android:textStyle="bold"
android:layout_centerHorizontal="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<RatingBar
android:id="@+id/rbRating"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:isIndicator="true"
android:layout_centerHorizontal="true"
android:layout_below="@+id/tvRatingTitle"
android:numStars="5"
android:rating="2.5"
android:stepSize="0.1" />
<CheckBox
android:id="@+id/chkMissing"
android:text="Zaznacz jeśli nie ma"
android:layout_centerHorizontal="true"
android:layout_below="@+id/rbRating"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
我也嘗試切換到android.support.v7.widget.AppCompatRatingBar
,但它並沒有任何區別。
編輯:
@Muhib皮拉尼的解決方案似乎是工作,但我有2個細小的問題:在Nexus 6P
1)明星的第一層是由幾個像素抵消(放大查看):
2)三星Galaxy J3(2016),它看起來是這樣的:
我很喜歡邊框,但我希望它們在空的星星上是綠色的(不是灰色的,背景應該是灰色的)。
捕獲視圖層次通過'工具 - > Android的 - >佈局Inspector',看看什麼是那些'RatingBar's之間的關鍵區別。一旦找到導致此行爲的屬性,找到實際原因將更容易。它看起來像是改變了alpha通道,或者以某種方式應用了色彩。 – azizbekian