How to make a scalable ListView item background colour?

I want to make a scalable ListView item background colour from green to red that scales every day by one tick. For example 365 days, from day 0 it's green and with each day it get's more red but not totaly red and finally on day 365 it get's totaly red. How can I make it happen?

Upvotes: 0

Views: 49

Answers (1)

Adib Faramarzi
Adib Faramarzi

Reputation: 4062

You can use ColorDrawable to create a color for each item, according to its color, and assign it as the item view's background. To get a color between two colors with a percentage, you can use ArgbEvaluator:

int color = new ArgbEvaluator().evaluate(getAdapterPosition()/365f, Color.GREEN, Color.RED);
ColorDrawable cd = new ColorDrawable(color);
view.setBackground(cd);

Upvotes: 1

Related Questions