Android:曲线走势图控件

本文介绍了如何在Android中创建一个用于显示盈利走势的自定义视图`ProfitTrendView`。该视图使用贝塞尔曲线来绘制平均值(`avg`)和目标值(`ta`)路径。通过初始化点、中点和控制点,然后使用`Canvas`进行绘制,实现了曲线的平滑展示。视图还包含了坐标轴和日期标签的绘制方法。
摘要由CSDN通过智能技术生成
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.Point;
import android.graphics.Typeface;
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;
import com..rf.R;
import com..rf.domain.ProfitTrend;
import com..rf.utils.CommonUtil;
import java.util.ArrayList;

/**
 * 盈利走势
 */
public class ProfitTrendView extends View {
    private Context context;
    private int dateTextSize;
    private Paint paint;
    private Path avgPath;
    private Path taPath;
    private ArrayList<Point> mAvgPoints = new ArrayList<>();
    private ArrayList<Point> mAvgMidPoints = new ArrayList<>();
    private ArrayList<Point> mAvgMidMidPoints = new ArrayList<>();
    private ArrayList<Point> mAvgControlPoints = new ArrayList<>();

    private ArrayList<Point> mTaPoints = new ArrayList<>();
    private ArrayList<Point> mTaMidPoints = new ArrayList<>();
    private ArrayList<Point> mTaMidMidPoints = new ArrayList<>();
    private ArrayList<Point> mTaControlPoints = new ArrayList<>();

    public ProfitTrendView(Context context) {
        super(context);
        init(context);
    }

    public ProfitTrendView(Context context, AttributeSet attrs) {
        super(context, attrs);
        init(context);
    }

    public ProfitTrendView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init(context);
    }

    private void init(Context context) {
        this.context = context;
        paint = new Paint();
        dateTextSize = CommonUtil.dipToPx(context, 11);
        avgPath = new Path();
        taPath = new Path();
    }

    private void initPoints(ProfitTrend trend) {
        mAvgPoints.add(new Point(10, 100));
        mAvgPoints.add(new Point(100, 300));
        mAvgPoints.add(new Point(250, 100));
        mAvgPoints.add(new Point(300, 350));
        mAvgPoints.add(new Point(400, 400));
        mAvgPoints.add(new Point(550, 100));
        mAvgPoints.add(new Point(600, 50));

        mTaPoints.add(new Point(100, 100));
        mTaPoints.add(new Point(50, 200));
        mTaPoints.add(new Point(200, 50));
        mTaPoints.add(new Point(2800, 350));
        mTaPoints.add(new Point(410, 10));
    
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值