In XML I don’t know if it’s possible.
In Java, one possible way is to create a Shape and build a Shapedrawable with her.
Doistriangulosdrawable.java
public class DoisTriangulosDrawable extends ShapeDrawable {
public DoisTriangulosDrawable(){
super();
setShape(new DoisTriangulosShape());
}
private class DoisTriangulosShape extends Shape {
@Override
public void draw(Canvas canvas, Paint paint) {
Path path = new Path();
path.setFillType(Path.FillType.INVERSE_EVEN_ODD);
Path path1 = new Path();
path1.setFillType(Path.FillType.INVERSE_EVEN_ODD);
paint.setStrokeWidth(0);
paint.setStyle(Paint.Style.FILL);
paint.setAntiAlias(true);
paint.setColor(Color.BLACK);
Point a = new Point(0, 0);
Point b = new Point(0, (int) getHeight());
Point c = new Point((int)getWidth(), (int)getHeight());
path.moveTo(a.x, a.y);
path.lineTo(b.x, b.y);
path.lineTo(c.x, c.y);
path.close();
canvas.drawPath(path, paint);
paint.setColor(Color.RED);
Point a1 = new Point(0, 0);
Point b1 = new Point((int)getWidth(),0);
Point c1 = new Point((int)getWidth(), (int)getHeight());
path1.moveTo(a1.x, a1.y);
path1.lineTo(b1.x, b1.y);
path1.lineTo(c1.x, c1.y);
path1.close();
canvas.drawPath(path1, paint);
}
}
}
To use, for example, as background of a Relativelayout:
RelativeLayout layout = (RelativeLayout) findViewById(R.id.layout);
ShapeDrawable background = new DoisTriangulosDrawable();
layout.setBackground(background);//Requer API16 ou superior
you want that "line" with 45º exactly or you want that line to go from one diagonal to the other?
– Boneco Sinforoso