2

我有一个 VectorDrawable xml,在为 android 创建表盘时,在 onDraw(Canvas canvas, Rect bounds) 方法中,我可以绘制这个 vectorDrawable 吗?像canvas.draw(vector.xml)一样,我不知道怎么做,请帮忙!

<vector xmlns:android="http://schemas.android.com/apk/res/android"
    android:height="64dp"
    android:width="64dp"
    android:viewportHeight="600"
    android:viewportWidth="600" >
    <group
        android:name="rotationGroup"
        android:pivotX="300.0"
        android:pivotY="300.0"
        android:rotation="45.0" >
        <path
            android:name="v"
            android:fillColor="#000000"
            android:pathData="M300,70 l 0,-70 70,70 0,0 -70,70z" />
    </group>
</vector>
4

1 回答 1

2

这是 WatchFaceService.Engine 的简单代码

private class Engine extends CanvasWatchFaceService.Engine {

    private Drawable mVectorDrawable;

    @Override
    public void onCreate(SurfaceHolder holder) {
        super.onCreate(holder);
        ...
        Resources resources = FooBarWatchFace.this.getResources();
        mVectorDrawable =resources.getDrawable(R.drawable.rounded);
    }

    @Override
    public void onDraw(Canvas canvas, Rect bounds) {
        int width = bounds.width();
        int height = bounds.height();
        ...
        mVectorDrawable.setBounds(0,0,width,height);
        mVectorDrawable.draw(canvas);
    }
}
于 2015-09-25T15:26:14.240 回答