Использовать пользовательский вид с помощью Android Canvas
и его методов drawLines()
и drawCircle()
Здесьэто то, как создать Пользовательские виды , и вот очень хороший, короткий учебник о том, как использовать эти методы для рисования любой фигуры.
Пример
// somewhere in the constructor, call this
private void init() {
mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mPaint.setColor(Color.RED);
mPaint.setStyle(Paint.Style.STROKE);
// mPaint.setStrokeWidth(SOME_VALUE);
...
}
// override onSizeChanged() to make your measurements.
// if you need 'finer' control, override onMeasure(), but be careful with that one
// (read its javadocs before you override it).
// measurements include shape and text locations and sizes, etc.
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
mTriangleVertices[0] = 0.2 * w; // x0
mTriangleVertices[1] = 0.15 * h; // y0
mTriangleVertices[2] = 0.5 * w; // x1
mTriangleVertices[3] = 0.85 * h; // y1
mTriangleVertices[4] = 0.8 * w; // x2
mTriangleVertices[5] = 0.15 * h; // y2
// other calculations...
}
// after you save your measurements to some fields, override onDraw().
// use all the tools you created and the info you gathers above here.
// avoid creating objects at all cost. read the docs for more info.
protected void onDraw(Canvas canvas) {
super.onDraw(canvas); // include this first, last or you can even omit it sometimes
canvas.drawLines(mTriangleVertices, 0, mTriangleVertices.length, mPaint);
// canvas.drawCircle(); canvas.drawOval(); etc..
}