나는 안드로이드 날씨 응용 프로그램에서 작업 중이며 온도에 적합한 색 (추울 때는 파란색, 뜨거울 때는 빨간색) 카드가 필요하지만 점차적으로 필요합니다. 40degrees는 밝은 빨간색이지만 20degrees는 황색처럼 보입니다.값에 따라 안드로이드 색 그라데이션 변경
이렇게하는 데 도움이되는 색상 선택 방법을 도와 줄 수 있습니까?
코드 :
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
이것은 테스트 코드 샘플과 비슷합니다. –