【发布时间】:2015-08-07 23:09:33
【问题描述】:
我需要画一个空白的圆圈,边距为 10 像素。我遇到的问题是我需要在 2 秒内模拟圆的绘制,然后开始在它的顶部绘制另一个颜色的圆。我正在使用自定义视图,并且尝试将我的逻辑实现到 onDraw 方法中,并每 50 毫秒使视图无效。问题是我无法画圆……我只画蹩脚的数字。有人知道我如何在不使用 canvas.drawCircle 方法的情况下绘制一个圆圈,因为该方法直接绘制圆圈而不使用动画。
我当前的代码
public class CustomAnimationView extends View{
private Canvas canvas;
private int count = 0;
private Paint paint;
private int mLeft;
private int mRight;
private int mBottom;
private int mTop;
public CustomAnimationView(Context context) {
super(context);
}
public CustomAnimationView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public CustomAnimationView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
setAttributes(attrs);
}
private void setAttributes(AttributeSet attrs) {
}
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
this.canvas = canvas;
if(paint == null){
paint = new Paint();
paint.setAntiAlias(true);
paint.setStyle(Style.STROKE);
paint.setStrokeWidth(10);
paint.setColor(Color.BLACK);
}
if(count<150){
drawFirstQuarter(count);
}
count++;
}
public void drawFirstQuarter(int count){
RectF oval = new RectF(mLeft, mTop, mRight, mBottom);
canvas.drawArc(oval, 90, 30, true, paint);
}
public void setRect(int top, int bottom, int left, int right){
mBottom = bottom;
mTop = top;
mLeft = left;
mRight = right;
}
}
现在我只是想画一个圆圈。
【问题讨论】:
-
你能发布你当前自定义视图的代码吗?
标签: android animation android-canvas