创建曲线customView布局

时间:2018-11-12 07:24:02

标签: android view custom-view

我创建了一个简单的自定义视图,该视图从RelativeLayout延伸

我创建了以下形状:

        firstPoint.set(0,100);
        secondPoint.set(getWidth(),100);
        thirdPoint.set(getWidth(),getHeight());
        fourthPoint.set(0,getHeight());

        mFirstCurveStartPoint.set((getWidth() / 5) * 4 , 100);
        mFirstCurveEndPoint.set((getWidth() /6) * 5, 0);

        mFirstCurveControlPoint1.set(mFirstCurveStartPoint.x + 100  , mFirstCurveStartPoint.y);
        mFirstCurveControlPoint2.set(mFirstCurveEndPoint.x -100 , mFirstCurveEndPoint.y);

enter image description here

我想成为我在图像上提到的红色曲线,但是我的代码curve section是错误的,并且我无法选择正确的数字来创建正确的曲线。.我认为该值是错误的:

 mFirstCurveControlPoint1.set(mFirstCurveStartPoint.x + 100  , mFirstCurveStartPoint.y);
 mFirstCurveControlPoint2.set(mFirstCurveEndPoint.x -100 , mFirstCurveEndPoint.y);

这是ondraw方法:

@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    mPath.lineTo(firstPoint.x,firstPoint.y);
    mPath.lineTo(mFirstCurveStartPoint.x,mFirstCurveStartPoint.y);
    mPath.lineTo(mFirstCurveEndPoint.x,mFirstCurveEndPoint.y);

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

    mPath.lineTo(thirdPoint.x,thirdPoint.y);
    mPath.lineTo(fourthPoint.x,fourthPoint.y);
    mPath.close();
    canvas.drawPath(mPath,mPaint);
}

0 个答案:

没有答案