October 2017
Intermediate to advanced
294 pages
6h 49m
English
Our basic implementation will be quite straightforward. Let's start by creating the class and its constructor:
public class Chart extends View { private Paint linePaint; public Chart(Context context, AttributeSet attrs) { super(context, attrs); linePaint = new Paint(); linePaint.setAntiAlias(true); linePaint.setColor(0xffffffff); linePaint.setStrokeWidth(8.f); linePaint.setStyle(Paint.Style.STROKE); }}
We've initialized a Paint object on our constructor, but this time we've set the style to Paint.Style.STROKE as we're only interested in drawing lines. Let's now add a method so whoever is using the custom view can set the data to render:
private float[] dataPoints;private float minValue;private float maxValue;private float ...
Read now
Unlock full access