RelativeLayout Android的自定义形状

时间:2015-10-20 21:49:45

标签: android android-layout relativelayout android-custom-view

是否可以在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);
}

但它不起作用。有什么想法吗?

Custom Shape

0 个答案:

没有答案