RatingBar变得半透明

Mak*_*ele 12 android android-view ratingbar

我使用的是RecyclerViewRatingBar每一个排.现在,有时RatingBars的一部分绘制不正确.离开屏幕并返回后,它们都恢复正常.我不知道为什么会发生这种情况,我甚至删除了任何样式,RatingBar所以它应该具有默认外观.

这是它的样子:

在此输入图像描述

在Nexus 6P(Android 7.1.1)上测试过.还在三星Galaxy J3(2016)(Android 5.1.1)上测试过,这里没有问题.

我还补充道

holder.rbRating.requestLayout();
Run Code Online (Sandbox Code Playgroud)

onBindViewHolder().它减少了一点问题,但它仍然存在.当我重复使用屏幕上的"坏"行时,它看起来很好.

这是行布局:

<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>
Run Code Online (Sandbox Code Playgroud)

我也尝试过转换android.support.v7.widget.AppCompatRatingBar,但它没有任何区别.

编辑:

@Muhib Pirani解决方案似乎有效,但我有两个小问题:

1)在Nexus 6P上,第一层星星偏移几个像素(放大查看):

在此输入图像描述

2)在三星Galaxy J3(2016)上看起来像这样:

在此输入图像描述

我对边界很好,但我希望它们在空星中也是绿色(不是灰色,背景应该是灰色的).

小智 5

我也面临同样的问题。我必须以编程方式将颜色设置为RatingBar这样,并且它有效:

LayerDrawable layerDrawable = (LayerDrawable) ratingBar.getProgressDrawable();
layerDrawable.getDrawable(2).setColorFilter(ContextCompat.getColor(context, R.color.colorPrimaryDark), PorterDuff.Mode.SRC_ATOP);
layerDrawable.getDrawable(1).setColorFilter(ContextCompat.getColor(context, R.color.colorPrimaryDark), PorterDuff.Mode.SRC_ATOP);
layerDrawable.getDrawable(0).setColorFilter(ContextCompat.getColor(context, R.color.editTextBor), PorterDuff.Mode.SRC_ATOP);//when not selected color.
Run Code Online (Sandbox Code Playgroud)

保持layerDrawable.getDrawable(2)layerDrawable.getDrawable(1)颜色相同。