我在我的onDraw()
方法中创建了一个圆圈,在圆圈周围画了一条线和一条线(箭头)。
public class Circle extends Activity {
public class OuterCircle extends View {
Paint paint = new Paint();
private Animation anim;
Path path = new Path();
private static final String s = "Hello world example";
public OuterCircle(Context context) {
super(context);
init();
}
private void init() {
paint.setColor(Color.WHITE);
paint.setStyle(Style.STROKE);
paint.setStrokeWidth(2);
paint.setAntiAlias(true);
}
private void drawStringOnCircle(Canvas c) {
path.addCircle(getWidth()/2, getHeight()/2, 180, Direction.CW);
c.drawTextOnPath(s, path, 0, 10, paint);
setLayerType(View.LAYER_TYPE_SOFTWARE, null);
}
private void createAnimation() {
anim = new RotateAnimation(0, 360, getWidth()/2, getHeight()/2);
anim.setRepeatMode(Animation.RESTART);
anim.setRepeatCount(Animation.INFINITE);
anim.setDuration(100L);
startAnimation(anim);
}
public void onDraw(Canvas c) {
int cx = getWidth()/2;
int cy = getHeight()/2;
if (anim == null) {
createAnimation();
}
c.drawCircle(cx, cy, 170, paint);
drawStringOnCircle(c);
c.drawLine(cx, cy, cx, cy+170, paint); // do not include this line in animation
}
}
OuterCircle = compassView;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
compassView = new DrawCompass(this);
setContentView(compassView);
}
}
我只想将动画应用于圆圈及其周围的文本(使用 Android 动画旋转圆圈及其周围的文本)。我在圆圈内绘制的线必须是静止的(动画不应应用于该线)。但是,上面的代码将动画应用于所有 3 Canvas
。我应该做出哪些改变?
另外,我想TextView
在圆圈中间添加一个。谁能分享我一些想法?