我在每行中使用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