Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/198.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
RelativeLayout Android的自定义形状_Android_Android Layout_Android Relativelayout_Android Custom View - Fatal编程技术网

RelativeLayout Android的自定义形状

RelativeLayout Android的自定义形状,android,android-layout,android-relativelayout,android-custom-view,Android,Android Layout,Android 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 Poi

是否可以在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);
}
但它不起作用。有什么想法吗


它画了什么吗?是的。。它正在画白色的部分。。我需要的是灰色部分和白色透明剂?有没有可能@Blackbelt为什么不使用图像?这将是我最后一个选择@OsamaAftab。。我试图改变一条路,但无论我改变什么。。它只画白色的部分