简体   繁体   English

如何绘制如下图像的形状

[英]How to draw shape like below image

Please help me to draw a shape like the image below. 请帮我画出如下图所示的形状。 I have tried many things, but none of the code worked. 我尝试了很多东西,但没有一个代码有效。

预期输出的图像,灰色上方的蓝色曲线

This is what I have tried 这就是我尝试过的

 private Point mFirstCurveStartPoint = new Point();
 private Point mFirstCurveEndPoint = new Point();

 .................................................
 .................................................

      mFirstCurveStartPoint.set((mNavigationBarWidth / 2) - (CURVE_CIRCLE_RADIUS * 2) - (CURVE_CIRCLE_RADIUS / 3), 0);
    // the coordinates (x,y) of the end point after curve
      mFirstCurveEndPoint.set(mNavigationBarWidth / 2, CURVE_CIRCLE_RADIUS + (CURVE_CIRCLE_RADIUS / 4));

    mFirstCurveControlPoint1.set(mFirstCurveStartPoint.x + CURVE_CIRCLE_RADIUS + (CURVE_CIRCLE_RADIUS / 4), mFirstCurveStartPoint.y);
    // the coordinates (x,y)  of the 2nd control point on a cubic curve
    mFirstCurveControlPoint2.set(mFirstCurveEndPoint.x - (CURVE_CIRCLE_RADIUS * 2) + CURVE_CIRCLE_RADIUS, mFirstCurveEndPoint.y);

     mPath.reset();
    mPath.moveTo(0, 0);
    mPath.lineTo(mFirstCurveStartPoint.x, mFirstCurveStartPoint.y);

    mPath.cubicTo(mFirstCurveControlPoint1.x, mFirstCurveControlPoint1.y,
            mFirstCurveControlPoint2.x, mFirstCurveControlPoint2.y,
            mFirstCurveEndPoint.x, mFirstCurveEndPoint.y);

is there any way to done this using Xml layout 有没有办法使用Xml布局完成此操作

Since I can't add comments because of low reputation, check this link . 由于声誉不佳我无法添加评论,请查看此链接

Adding another link if you're going to use Java here , in Areas section some great example how to achieve your shape using setVisible . 如果你打算在这里使用Java,可以在Areas部分添加另一个链接,这是一个很好的例子,说明如何使用setVisible实现你的形状。

If you have an image in svg format, use Asset Studio to convert it to xml drawable. 如果您有svg格式的图像,请使用Asset Studio将其转换为xml drawable。 Otherwise, use code like that: 否则,使用这样的代码:

<vector xmlns:android="http://schemas.android.com/apk/res/android"
    android:width="500dp"
    android:height="300dp"
    android:viewportWidth="500"
    android:viewportHeight="300">
  <path
      android:pathData="M0,0h500v300h-500z"
      android:fillColor="#e3e3e3"/>
  <path
      android:pathData="M0,80C0,250 487,104 550,247L500,300L0,300"
      android:fillColor="#3e47cb"/>
</vector>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM