1
我正在开发一款android天气应用程序,我需要一张卡片的背景以使其具有足够的颜色以适应温度(蓝色表示冷,红色表示热度),但我需要逐渐使用它40度为鲜红色,20度为淡黄色。基于值的Android颜色渐变变化
你能帮我选择一种颜色选择方法吗?
代码:
public class WeatherContentAdapter extends RecyclerView.Adapter<WeatherContentAdapter.WeatherContentVH> {
private List<WeatherInfo> mWeatherInfoList;
public WeatherContentAdapter() {
this.mWeatherInfoList = new ArrayList<>();
mWeatherInfoList.add(new DailyWeatherInfo("Monday", 10, WeatherConditions.RAINY));
mWeatherInfoList.add(new DailyWeatherInfo("Tuesday", 15, WeatherConditions.RAINY));
mWeatherInfoList.add(new DailyWeatherInfo("Wednesday", 20, WeatherConditions.FOGGY));
mWeatherInfoList.add(new DailyWeatherInfo("Thursday", 25, WeatherConditions.CLOUDY));
mWeatherInfoList.add(new DailyWeatherInfo("Friday", 30, WeatherConditions.CLOUDY));
mWeatherInfoList.add(new DailyWeatherInfo("Saturday", 35, WeatherConditions.CLEAR));
mWeatherInfoList.add(new DailyWeatherInfo("Sunday", 40, WeatherConditions.CLEAR));
}
@Override
public WeatherContentVH onCreateViewHolder(ViewGroup parent, int viewType) {
LayoutInflater layoutInflater = LayoutInflater.from(parent.getContext());
View inflatedView = layoutInflater.inflate(R.layout.item_content, parent, false);
return new WeatherContentVH(inflatedView);
}
@Override
public void onBindViewHolder(WeatherContentVH holder, int position) {
holder.mWeatherTempTV.setText(mWeatherInfoList.get(position).mTemperature + "Celsius degrees");
holder.mWeatherCard.setCardBackgroundColor(???);
}
@Override
public int getItemCount() {
return mWeatherInfoList.size();
}
class WeatherContentVH extends RecyclerView.ViewHolder {
TextView mWeatherTempTV;
CardView mWeatherCard;
public WeatherContentVH(View itemView) {
super(itemView);
mWeatherTempTV = (TextView) itemView.findViewById(R.id.ic_tv_weather_temp);
mWeatherCard = (CardView) itemView.findViewById(R.id.ic_cv_weather);
}
}
}
向我们展示您的工作...任何代码? – FiN
这更像是一个测试代码示例 –