I have create a subclass of View and overwritten onDraw() - see some
test code below.
It draws a line consisting of some points. Before the line is drawn
the canvas is rotated and restore after the drawing.
The angle by which the canvas is rotated increases by 5 degrees every
time onDraw() is called.
The view is invalidated about once a second causing the view to be
redrawn.
Due to the rotated canvas the line drawn looks like a clock hand
rotating counter-clockwise.
This works - but not always. Sometimes the line is not drawn for one
or more seconds, although I know from the log statement that onDraw()
was called. Sometimes means: The line may be not shown after 8
seconds, then again after 35 seconds and so on.
If the canvas is not rotated the problem does not occur.
This also happens when I use a SurfaceView instead of a View.
It does not only occur in the simulator but also on my G1 - both using
Android 1.6.
Axel
public class NoMapView extends View {
private int angle;
private Paint paint;
public NoMapView(Context context) {
super(context);
}
public NoMapView(Context context, AttributeSet attrs, int
defStyle) {
super(context, attrs, defStyle);
}
public NoMapView(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
if(paint == null) {
paint = new Paint(Paint.ANTI_ALIAS_FLAG);
paint.setAntiAlias(true);
paint.setColor(Color.MAGENTA);
paint.setStyle(Paint.Style.FILL);
paint.setStrokeWidth(1);
}
Point center = new Point(getWidth() / 2, getHeight() / 2);
canvas.save();
canvas.rotate(-angle, center.x, center.y);
for(int i=160; i<180; i++) {
canvas.drawPoint(i, i, paint);
}
canvas.restore();
// log.info("angle=" + angle);
angle+=5;
if(angle == 360) {
angle = 0;
}
}
}
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en