我是 Canvas 的新手并在 Android 中绘图,我只是从这个网站上获取了代码,但我设法对其进行了调整,但我发现很难更改边框样式和边框颜色。
我希望边框只是一个简单的黑色方形边框,没有花哨的波浪和色谱。
这是 onCreate 函数中的代码,我已经设法将边框的波浪度降到最低,但仍然有微小的颠簸和转弯。
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_main);
float[] outerR = new float[] { 12, 12, 12, 12, 0, 0, 0, 0 };
RectF inset = new RectF(6, 6, 6, 6);
float[] innerR = new float[] { 12, 12, 0, 0, 12, 12, 0, 0 };
mDrawables = new ShapeDrawable[2];
mDrawables[0] = new ShapeDrawable(new RoundRectShape(outerR, inset, null));
//mDrawables[0].getPaint().setShader(makeSweep());
mDrawables[1] = new ShapeDrawable(new RoundRectShape(outerR, inset, innerR));
//mDrawables[1].getPaint().setShader(makeLinear());
PathEffect mPathEffect1 = new DiscretePathEffect(1, 1);
PathEffect mPathEffect2 = new CornerPathEffect(1);
mDrawables[0].getPaint().setPathEffect(new ComposePathEffect(mPathEffect2, mPathEffect1));
RelativeLayout layout = (RelativeLayout) findViewById(R.id.myDrawing);
layout.setBackgroundDrawable(mDrawables[0]);
activity = this;
//mView = new DrawingView(this);
mView = new SignatureView(activity, null);
layout.addView(mView, new LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT));
init();
mEmboss = new EmbossMaskFilter(new float[] { 1, 1, 1 }, 0.4f, 6, 3.5f);
mBlur = new BlurMaskFilter(8, BlurMaskFilter.Blur.NORMAL);
}
抱歉,我知道这可能是一项简单的任务,但我完全被难住了。
编辑 - 好吧,我设法让它变成纯黑色,我刚刚删除了 mDrawables[0/1].getPaint() 线,它变成了黑色,我现在唯一的问题是让它完全笔直。