我有一个VectorDrawable xml,当为Android创建表盘时,在onDraw(Canvas canvas, Rectbounds)方法中,我可以绘制这个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>
最佳答案
这是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);
}
}
关于Android CanvasWatchFaceService.Engine onDraw 绘制矢量xml,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30523414/