我使用下面的代码绘制算法。但是如何使其可滚动(垂直和水平)? 问题是,在纵向模式下,绘图超出了显示范围,但是当我将其缩小时,用户无法再阅读文本。
public class legende extends View {
private Paint paint;
private RectF einstiegRectF;
private RectF massnahmenRectF;
Path arrowPath;
public legende(Context context) {
super(context);
init();
}
public void init(){
paint = new Paint();
einstiegRectF = new RectF(20, 20, 820, 220);
arrowPath = new Path();
massnahmenRectF = new RectF(20, 320, 820, 420);
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
paint.setStyle(Paint.Style.FILL);
paint.setColor(Color.WHITE);
canvas.drawPaint(paint);
paint.setColor(Color.parseColor("#ccd2ec"));
paint.setStyle(Paint.Style.FILL);
canvas.drawOval(einstiegRectF, paint);
paint.setColor(Color.BLACK);
paint.setStyle(Paint.Style.STROKE);
canvas.drawOval(einstiegRectF, paint);
paint.setTextSize(35);
canvas.drawText("Einstiegsbedingungen / Fortsetzung von ...", 100, 130, paint);
paint.setStrokeWidth(8);
canvas.drawLine(420, 220, 420, 300, paint);
arrowPath.moveTo(420, 300);
arrowPath.lineTo(430, 300);
arrowPath.lineTo(420, 310);
arrowPath.lineTo(410, 300);
arrowPath.close();
canvas.drawPath(arrowPath, paint);
paint.setStrokeWidth(4);
paint.setColor(Color.BLACK);
paint.setStyle(Paint.Style.STROKE);
canvas.drawRect(massnahmenRectF, paint);
paint.setStrokeWidth(0);
canvas.drawText("Maßnahme", 350, 382, paint);
paint.setStrokeWidth(4);
Path rectArrow = new Path();
rectArrow.moveTo(840, 370);
rectArrow.lineTo(940, 320);
rectArrow.lineTo(1240, 320);
rectArrow.lineTo(1240, 420);
rectArrow.lineTo(940, 420);
rectArrow.close();
canvas.drawPath(rectArrow, paint);
}
}