是否可以在relativelayout上创建如下图所示的自定义形状?
我尝试过这段代码:
@Override
protected void onDraw(Canvas canvas) {
int w = this.getWidth() - (this.getWidth()/4);
int w2 = this.getWidth() - (this.getWidth()/6);
int h = this.getHeight();
Point a = new Point(0, 0);
Point b = new Point(w, 0);
Point c = new Point(w2, h);
Point d = new Point(0, h);
Path path = new Path();
path.moveTo(a.x, a.y);
path.lineTo(b.x, b.y);
path.lineTo(c.x, c.y);
path.lineTo(d.x, d.y);
path.lineTo(a.x, a.y);
path.close();
Paint p = new Paint();
p.setColor(Color.WHITE);
canvas.drawPath(path, p);
super.onDraw(canvas);
}
但它不起作用。有什么想法吗?