メソッドで円を作成し、円の周りに文字列と線 (矢印) を描画しました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
また、円の真ん中にを追加したいです。誰でもアイデアを共有できますか?