NativeScript View _createUI访问画布?

时间:2016-04-19 01:04:23

标签: android-canvas nativescript

我想通过NativeScript访问Canvas,但我似乎无法找到桥接入口点。因为_CreateUI没有在画布中传递,而Java中的onDraw就是这样。

我想做NativeScript Equiv:

@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); 
} 

由于 菲尔

1 个答案:

答案 0 :(得分:2)

以下是如何在NativeScript Android应用中构建 Canvas 的快速示例。使用带有NativeScript的Placeholder component创建本机组件,除非您想编写插件/模块,否则您将完全采用不同的方法。

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;`