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
這更像是一個測試代碼示例 –