gpt4 book ai didi

java - 如何为可绘制的线条形状制作圆角破折号或圆点

转载 作者:行者123 更新时间:2023-11-29 18:27:15 25 4
gpt4 key购买 nike

有没有一种方法可以使帽/点变圆,如附图所示?

enter image description here

<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="line">

<stroke
android:width="2dp"
android:color="@color/grey"
android:dashWidth="3dp"
android:dashGap="3dp" />

</shape>

注意

伙计们,我知道如何制作虚线,我想问的是如何制作“圆角”破折号。!!看看这张来自 Adob​​e XD 的图片就知道我的意思了..!

enter image description here

最佳答案

您可以使用自定义 View 并在 Canvas 上绘图来实现目标。请试试这个并根据您的需要调整尺寸/样式:

public class RoundedDashView extends View {

public enum Orientation {
VERTICAL,
HORIZONTAL
}

private Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
private Path path = new Path();
private Orientation orientation = Orientation.HORIZONTAL;

public RoundedDashView(Context context) {
super(context);
init();
}

public RoundedDashView(Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
init();
}

public RoundedDashView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init();
}

public RoundedDashView(Context context, @Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
init();
}

private void init() {
paint.setStyle(Paint.Style.STROKE);
paint.setStrokeCap(Paint.Cap.ROUND);
paint.setStrokeWidth(10);
paint.setColor(Color.GRAY);
paint.setPathEffect(new DashPathEffect(new float[]{20, 25}, 20));
}

@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
path.reset();
if (orientation == Orientation.VERTICAL) {
path.moveTo(getWidth() / 2, 0);
path.quadTo(getWidth() / 2, getHeight() / 2, getWidth() / 2, getHeight());
} else {
path.moveTo(0, getHeight() / 2);
path.quadTo(getWidth() / 2, getHeight() / 2, getWidth(), getHeight() / 2);
}
canvas.drawPath(path, paint);
}

public void setOrientation(Orientation orientation) {
this.orientation = orientation;
invalidate();
}
}

关于java - 如何为可绘制的线条形状制作圆角破折号或圆点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58178998/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com