NativeScript 视图 _createUI 正在访问 Canvas?
NativeScript View _createUI Accessing Canvas?
我想通过 NativeScript 访问 Canvas,但我似乎找不到桥接入口点。因为 _CreateUI 不传递 canvas,而 Java 中的 onDraw 传递。
我想做 NativeScript 等价于:
@Override
protected void onDraw(Canvas canvas) {
// floor the border width to avoid gaps between the border and the image
float roundedBorderWidth = (float) Math.floor(this.borderWidth);
float innerRadius = Math.max(0, this.cornerRadius - roundedBorderWidth);
// The border width is included in the padding so there is no need for
// clip if there is no inner border radius.
if (innerRadius != 0) {
this.rect.set(
roundedBorderWidth,
roundedBorderWidth,
this.getWidth() - roundedBorderWidth,
this.getHeight() - roundedBorderWidth);
this.path.reset();
this.path.addRoundRect(rect, innerRadius, innerRadius, android.graphics.Path.Direction.CW);
canvas.clipPath(this.path);
}
super.onDraw(canvas);
}
谢谢
菲尔
这里是关于如何在 NativeScript Android 应用程序中构建 Canvas 的快速示例。使用 Placeholder component 和 NativeScript 来创建原生组件,除非你想写一个 plugin/module,否则你会采取完全不同的方法。
XML:
<Page> <Placeholder creatingView="createCanvas" height="200" /> </Page>
JavaScript代码:
function createCanvas(args) {
var canvas = new android.graphics.Canvas(); // construct an empty canvas
args.view = canvas; // this puts the canvas on the interface where the placeholder is.
}
exports createCanvas = createCanvas;`
我想通过 NativeScript 访问 Canvas,但我似乎找不到桥接入口点。因为 _CreateUI 不传递 canvas,而 Java 中的 onDraw 传递。
我想做 NativeScript 等价于:
@Override
protected void onDraw(Canvas canvas) {
// floor the border width to avoid gaps between the border and the image
float roundedBorderWidth = (float) Math.floor(this.borderWidth);
float innerRadius = Math.max(0, this.cornerRadius - roundedBorderWidth);
// The border width is included in the padding so there is no need for
// clip if there is no inner border radius.
if (innerRadius != 0) {
this.rect.set(
roundedBorderWidth,
roundedBorderWidth,
this.getWidth() - roundedBorderWidth,
this.getHeight() - roundedBorderWidth);
this.path.reset();
this.path.addRoundRect(rect, innerRadius, innerRadius, android.graphics.Path.Direction.CW);
canvas.clipPath(this.path);
}
super.onDraw(canvas);
}
谢谢 菲尔
这里是关于如何在 NativeScript Android 应用程序中构建 Canvas 的快速示例。使用 Placeholder component 和 NativeScript 来创建原生组件,除非你想写一个 plugin/module,否则你会采取完全不同的方法。
XML:
<Page> <Placeholder creatingView="createCanvas" height="200" /> </Page>
JavaScript代码:
function createCanvas(args) {
var canvas = new android.graphics.Canvas(); // construct an empty canvas
args.view = canvas; // this puts the canvas on the interface where the placeholder is.
}
exports createCanvas = createCanvas;`