Android 如何在选定的底部导航的顶部边缘获得曲线?
我刚开始做一个项目,想把弯曲的bottomnavigationview放得更像是用户点击凹凸产生的波浪。 像这样 我几乎找到了一个库,在这个库中,开发人员通过向项目添加topedgetreatment完成了出色的工作。然而,我更感兴趣的是用贝塞尔曲线来做这个。我查了很多密码,但都没用 有人能帮我得到一个提示,关于如何画一个凹凸动画 下面是我试图做的,但那不是我想要实现的Android 如何在选定的底部导航的顶部边缘获得曲线?,android,canvas,path,bezier,curve,Android,Canvas,Path,Bezier,Curve,我刚开始做一个项目,想把弯曲的bottomnavigationview放得更像是用户点击凹凸产生的波浪。 像这样 我几乎找到了一个库,在这个库中,开发人员通过向项目添加topedgetreatment完成了出色的工作。然而,我更感兴趣的是用贝塞尔曲线来做这个。我查了很多密码,但都没用 有人能帮我得到一个提示,关于如何画一个凹凸动画 下面是我试图做的,但那不是我想要实现的 public class CurvedBottomNavigationView extends BottomNavigati
public class CurvedBottomNavigationView extends BottomNavigationView {
private Path mPath;
private Paint mPaint;
/** the CURVE_CIRCLE_RADIUS represent the radius of the fab button */
public final int CURVE_CIRCLE_RADIUS = 256 / 3;
// the coordinates of the first curve
public Point mFirstCurveStartPoint = new Point();
public Point mFirstCurveEndPoint = new Point();
public Point mFirstCurveControlPoint2 = new Point();
public Point mFirstCurveControlPoint1 = new Point();
//the coordinates of the second curve
@SuppressWarnings(“FieldCanBeLocal”)
public Point mSecondCurveStartPoint = new Point();
public Point mSecondCurveEndPoint = new Point();
public Point mSecondCurveControlPoint1 = new Point();
public Point mSecondCurveControlPoint2 = new Point();
public int mNavigationBarWidth;
public int mNavigationBarHeight;
public CurvedBottomNavigationView(Context context) {
super(context);
init();
}
public CurvedBottomNavigationView(Context context, AttributeSet attrs) {
super(context, attrs);
init();
}
public CurvedBottomNavigationView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init();
}
private void init() {
mPath = new Path();
mPaint = new Paint();
mPaint.setStyle(Paint.Style.FILL_AND_STROKE);
mPaint.setColor(Color.WHITE);
setBackgroundColor(Color.TRANSPARENT);
}
@Override
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
super.onLayout(changed, left, top, right, bottom);
}
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
super.onSizeChanged(w, h, oldw, oldh);
// get width and height of navigation bar
// Navigation bar bounds (width & height)
mNavigationBarWidth = getWidth();
mNavigationBarHeight = getHeight();
// the coordinates (x,y) of the start point before curve
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));
// same thing for the second curve
mSecondCurveStartPoint = mFirstCurveEndPoint;
mSecondCurveEndPoint.set((mNavigationBarWidth / 2) + (CURVE_CIRCLE_RADIUS * 2) + (CURVE_CIRCLE_RADIUS / 3), 0);
// the coordinates (x,y) of the 1st control point on a cubic curve
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);
mSecondCurveControlPoint1.set(mSecondCurveStartPoint.x + (CURVE_CIRCLE_RADIUS * 2) — CURVE_CIRCLE_RADIUS, mSecondCurveStartPoint.y);
mSecondCurveControlPoint2.set(mSecondCurveEndPoint.x — (CURVE_CIRCLE_RADIUS + (CURVE_CIRCLE_RADIUS / 4)), mSecondCurveEndPoint.y);
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
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);
mPath.cubicTo(mSecondCurveControlPoint1.x, mSecondCurveControlPoint1.y,
mSecondCurveControlPoint2.x, mSecondCurveControlPoint2.y,
mSecondCurveEndPoint.x, mSecondCurveEndPoint.y);
mPath.lineTo(mNavigationBarWidth, 0);
mPath.lineTo(mNavigationBarWidth, mNavigationBarHeight);
mPath.lineTo(0, mNavigationBarHeight);
mPath.close();
canvas.drawPath(mPath, mPaint);
}
}