Search code examples
androidandroid-recyclerviewandroid-viewtransparencyandroid-viewholder

Why is setAlpha() not working in RecyclerViews?


I am trying to change the transparency of item-views in a RecyclerView according to certain user inputs.

if (quantity>0) {
    holder.itemView.setAlpha((float) 1);
} else {
    holder.itemView.setAlpha((float) 0.65);
}

Changing alpha from 0.65 to 1 works fine when quantity > 0. But the reverse is not working on the other case. When debugging, it clearly shows going through the line holder.itemView.setAlpha((float) 0.65); However, alpha is not reduced. Any clue about what's going on?


Solution

  • I had this same problem. Instead of changing the alpha of the itemView, give an name to your root layout and change its alpha instead, as the recyclerview animations handle the itemView alpha animation making it not work.