我想在三角形上绘制文字我这样做:
for(Widgets widget: wid) {
if(widget.getTypeString().contains("Triangle")) {
LOGGER.info(widget.getName());
paintTriangle.setAntiAlias(true);
seuils = JSONUtils.getSeuilAndColor(widget);
value = JSONUtils.getValue(widget);
int color = this.getColorSeuil();
paintTriangle.setColor(color);
paintTriangle.setStrokeWidth(2);
paintTriangle.setStyle(Paint.Style.FILL);
if(canvas.getWidth() < c.x){
a.set(150, a.y + 300);
b.set(10, b.y + 300);
c.set(310, c.y + 300);
path.moveTo(a.x, a.y);
}
path.lineTo(a.x, a.y);
path.lineTo(b.x, b.y);
path.lineTo(c.x, c.y);
canvas.drawPath(path, paintTriangle);
canvas.drawText(widget.getName(), b.x+20, b.y-20, paintText);
a.set(a.x + 310, a.y);
b.set(b.x + 310, b.y);
c.set(c.x + 310, c.y);
path.moveTo(a.x, a.y);
}
}
小部件包含构建此三角形的一些信息:
所以我的问题是如果我有一个以上的三角形,文字在第一个形状下但在最后一个。
我不明白,因为它适用于方法Rect和Circle,我也是这样做的。
答案 0 :(得分:0)
我忘记为每个Triangle创建一个新路径,有新代码:
for(Widgets widget: wid) {
if(widget.getTypeString().contains("Triangle")) {
LOGGER.info(widget.getName());
Path path = new Path();
path.setFillType(Path.FillType.EVEN_ODD);
path.moveTo(a.x, a.y);
// Lissage des lignes, meilleur rendu à l'écran
paintTriangle.setAntiAlias(true);
// Initialisation des paramètres
seuils = JSONUtils.getSeuilAndColor(widget);
value = JSONUtils.getValue(widget);
// Récuperation de la couleur du seuil
int color = this.getColorSeuil();
String hexcolor = String.format("#%06X", (0xFFFFFF & color));
// Colorier le triangle en fonction du dépassement du seuil
paintTriangle.setColor(color);
// Largeur de la bordure du triangle
paintTriangle.setStrokeWidth(2);
paintTriangle.setStyle(Paint.Style.FILL);
// Création triangle dynamique
if(canvas.getWidth() < c.x){
a.set(150, a.y + 300);
b.set(10, b.y + 300);
c.set(310, c.y + 300);
path.moveTo(a.x, a.y);
}
path.lineTo(a.x, a.y);
path.lineTo(b.x, b.y);
path.lineTo(c.x, c.y);
path.close();
canvas.drawPath(path, paintTriangle);
canvas.drawText(widget.getName(), b.x+20, b.y-20, paintText);
a.set(a.x + 310, a.y);
b.set(b.x + 310, b.y);
c.set(c.x + 310, c.y);
}
}