我正在尝试使用画布绘制一个椭圆,但它永远不会被绘制。这是我的自定义视图代码。我也用过setWillNotDraw(false)
,屏幕上仍然没有绘制任何内容。
public class Myview extends View {
Paint paint;
RectF rect;
public Myview(Context context) {
super(context);
init();
setWillNotDraw(false);
}
public Myview(Context context, AttributeSet attrs) {
super(context, attrs);
init();
setWillNotDraw(false);
}
public Myview(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
init();
setWillNotDraw(false);
}
private void init() {
rect = new RectF(0.1 f, 0.1 f, getWidth(), getHeight());
paint = new Paint();
paint.setShader(new LinearGradient(0.40 f, 0.0 f, 100.60 f, 100.0 f,
Color.parseColor("#ffffff"),
Color.parseColor("#Ffffff"),
Shader.TileMode.CLAMP));
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
setMeasuredDimension(200, 200);
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
canvas.drawOval(rect, paint);
}
}
有什么建议么?