我需要在我的项目中创建贝塞尔曲线。为此,我正在用油漆绘制视图,但问题是我没有得到满足我需要的确切形状,如下图所示。因此,请帮助我解决您的解决方案以及我的代码中的更改或修改。提前致谢。
我用来创建贝塞尔曲线的代码:
public class DrawView extends View {
public DrawView (Context context) {
super (context);
}
protected void onDraw (Canvas canvas) {
super.onDraw (canvas);
Paint pLine = new Paint () {{
setStyle (Paint.Style.STROKE);
setAntiAlias (true);
setStrokeWidth (1.5f);
setColor (Color.RED); // Line color
}};
Paint pLineBorder = new Paint () {{
setStyle (Paint.Style.STROKE);
setAntiAlias (true);
setStrokeWidth (3.0f);
setStrokeCap (Cap.ROUND);
setColor (Color.RED); // Darker version of the color
}};
Path p = new Path ();
Point mid = new Point ();
// ...
Point start =new Point (30,90);
Point end =new Point (canvas.getWidth ()-30,140);
mid.set ((start.x + end.x) / 2, (start.y + end.y) / 2);
// Draw line connecting the two points:
p.reset ();
p.moveTo (start.x, start.y);
p.quadTo ((start.x + mid.x) / 2, start.y, mid.x, mid.y);
p.quadTo ((mid.x + end.x) / 2, end.y, end.x, end.y);
canvas.drawPath (p, pLineBorder);
canvas.drawPath (p, pLine);
}
}
主要活动
public class MainActivity extends Activity {
private DrawView drawView;
@Override
protected void onCreate (Bundle savedInstanceState) {
super.onCreate (savedInstanceState);
drawView = new DrawView (this);
setContentView (drawView);
}
}
我的实际需求:
我得到的输出: