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));
Android:曲线走势图控件
最新推荐文章于 2024-07-14 14:09:46 发布
本文介绍了如何在Android中创建一个用于显示盈利走势的自定义视图`ProfitTrendView`。该视图使用贝塞尔曲线来绘制平均值(`avg`)和目标值(`ta`)路径。通过初始化点、中点和控制点,然后使用`Canvas`进行绘制,实现了曲线的平滑展示。视图还包含了坐标轴和日期标签的绘制方法。
摘要由CSDN通过智能技术生成