我有一个VectorDrawable xml,在为android创建一个watch face时,在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>
答案 0 :(得分:1)
以下是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);
}
}