package com.app.map.widget;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.DashPathEffect;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.Rect;
import android.graphics.RectF;
import android.os.Handler;
import android.os.Message;
import android.util.AttributeSet;
import android.widget.HorizontalScrollView;
import com.app.map.R;
import com.app.map.model.bean.PointBean;
import com.app.map.model.bean.WeatherBean;
import java.util.ArrayList;
import java.util.List;
public class weatherView extends HorizontalScrollView {
private Context context;
private Paint mPaint;
private Rect mBound;
private int itemWeight;
private int itemSize = 0;
private int width;
private int height;
private List<String> str;
private List<Integer> tempOne;
private List<Integer> tempTwo;
private int tempMax = 0;
private int tempMin = 0;
private List<String> riqiStr;
private List<String> weatherStrOne;
private List<Bitmap> weatherImgOme;
private List<Bitmap> weatherImgTwo;
private List<String> weatherStrTwo;
private List<String> windStr;
private List<String> windLeverStr;
private List<String> airQualityColor;
private List<String> airQuality;
private Canvas mCanvas;
private static final int DRAW_ONE_PIC = 1001;
private static final int DRAW_TWO_PIC = 1002;
public weatherView(Context context) {
super(context);
this.context = context;
initData();
}
public weatherView(Context context, AttributeSet attrs) {
super(context, attrs);
this.context = context;
initData();
}
public weatherView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
this.context = context;
initData();
}
private void initData() {
mPaint = new Paint();
mPaint.setTextSize(dip2px(context, 10));
mBound = new Rect();
itemWeight = dip2px(context, 55);//每一个的宽度
}
/**
* 设置数据
*/
public void setShowData(WeatherBean weatherBean) {
itemSize = weatherBean.getWeekStr().size();//总共个数
tempMax = weatherBean.getMaxTemp();//最大值
tempMin = weatherBean.getMinTemp();//最小值
str = weatherBean.getWeekStr();//星期
riqiStr = weatherBean.getRiqiStr();//日期
weatherStrOne = weatherBean.getWeatherStrOne();//天气
weatherImgOme = weatherBean.getWeatherImgOme();//天气图片
tempOne = weatherBean.getTempOne();//第一条温度数据
tempTwo = weatherBean.getTempTwo();//第二条温度数据
weatherImgTwo = weatherBean.getWeatherImgTwo();//天气图片
weatherStrTwo = weatherBean.getWeatherStrTwo();//天气
windStr = weatherBean.getWindStr();//风的类型
windLeverStr = weatherBean.getWindLeverStr();//风的级别
airQualityColor = weatherBean.getAirQualityColor();//质量背景色
airQuality = weatherBean.getAirQuality();//质量
invalidate();
}
@Override
protected void onDraw(final Canvas canvas) {
mCanvas = canvas;
super.onDraw(canvas);
width = getWidth();
height = getHeight();
//设置背景色
setBackgroundColor(Color.parseColor("#88253643"));
//画分割线
mPaint.setColor(getResources().getColor(R.color.transparent_white_55));
mPaint.setStrokeWidth(dip2px(context, 0.5f));
画天气预报 折线图 源代码
最新推荐文章于 2024-10-10 14:39:11 发布
本文详细介绍了如何使用编程语言绘制天气预报的折线图,从数据准备到图表展示,涵盖画布设置、坐标轴定义、数据点绘制等关键步骤,帮助读者理解并实现自己的天气变化可视化工具。
摘要由CSDN通过智能技术生成